Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java compilation problem - Caused by package access

Reply
Thread Tools

Java compilation problem - Caused by package access

 
 
JSR
Guest
Posts: n/a
 
      12-10-2003
If class TestPackage and DefPack are in 2 separate files, how can we
access DefPack from TestPackage?

Note -
1. TestPackage is in package testapps and DefPack is in the default
package space. This is the problem.
2. If I were to comment out the package statement within
TestPackage.java, this example would compile.
3. I need to be able to compile with the pacakge specifications being
the way they are.

// Compilation unit - TestPackage.java

package testapps;

public class TestPackage {
public static void main(String[] args) {
new DefPack();
}
}


// Compilation unit - DefPack.java

public class DefPack {
public DefPack() {
System.out.println("DefPack created");
}
}
 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      12-11-2003
JSR wrote:

> If class TestPackage and DefPack are in 2 separate files, how can we
> access DefPack from TestPackage?
>
> Note -
> 1. TestPackage is in package testapps and DefPack is in the default
> package space. This is the problem.
> 2. If I were to comment out the package statement within
> TestPackage.java, this example would compile.
> 3. I need to be able to compile with the pacakge specifications being
> the way they are.


You really can't do that. You can not import classes from the default (== no
package statement given) package. So you'll never be able to reach DefPack
from TestPackage.

The only solution is to put DefPack in a proper package.

>
> // Compilation unit - TestPackage.java
>
> package testapps;
>
> public class TestPackage {
> public static void main(String[] args) {
> new DefPack();
> }
> }
>
>
> // Compilation unit - DefPack.java
>
> public class DefPack {
> public DefPack() {
> System.out.println("DefPack created");
> }
> }


--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
JSR
Guest
Posts: n/a
 
      12-11-2003
Christophe Vanfleteren <> wrote in message news:<1tOBb.71530$>...
> JSR wrote:
>
> > If class TestPackage and DefPack are in 2 separate files, how can we
> > access DefPack from TestPackage?
> >
> > Note -
> > 1. TestPackage is in package testapps and DefPack is in the default
> > package space. This is the problem.
> > 2. If I were to comment out the package statement within
> > TestPackage.java, this example would compile.
> > 3. I need to be able to compile with the pacakge specifications being
> > the way they are.

>
> You really can't do that. You can not import classes from the default (== no
> package statement given) package. So you'll never be able to reach DefPack
> from TestPackage.
>
> The only solution is to put DefPack in a proper package.
>
> >
> > // Compilation unit - TestPackage.java
> >
> > package testapps;
> >
> > public class TestPackage {
> > public static void main(String[] args) {
> > new DefPack();
> > }
> > }
> >
> >
> > // Compilation unit - DefPack.java
> >
> > public class DefPack {
> > public DefPack() {
> > System.out.println("DefPack created");
> > }
> > }



Thanks for the info. I unfortunately have to integrate my code with
some third party code written this way.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation error with seperate compilation C__chp C++ 4 02-15-2008 03:57 PM
"Convert to Web Application" caused compilation errors. clintonb ASP .Net 0 06-22-2007 06:08 PM
Some "anti-virus" site BLOCKED my access to Goggle site thus caused "blaster"?? Black Tractor Computer Support 6 02-24-2006 03:18 AM
fphdl package compilation error in Modelsim vedpsingh@gmail.com VHDL 4 07-08-2005 12:53 PM
easy compilation of a package tree? flupke Java 5 06-09-2004 03:21 PM



Advertisments