This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Package file inter-access

 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
two file lie on the same dir(f:\javapackage).
the content of bbb.java file is:

the content of aaa.java file is:

When I compile the aaa.java file, I get the following message:
---------- Compile (javac.exe) ----------
aaa.java:5: cannot resolve symbol
symbol : class bbb
location: class javapackage.aaa
bbb b;
^
1 error

I remember that classes in the same package can inter-access. Why can the aaa class not get the bbb class in this situation? What's wrong with it?
[ October 22, 2002: Message edited by: Mikey Chen ]
[ October 22, 2002: Message edited by: Mikey Chen ]
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compiling the bbb.java first or try compiling with a wildcard.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put a .(dot) in your CLASSPATH
Rene
 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Barnes:
Try compiling the bbb.java first or try compiling with a wildcard.

1.I have compiled bbb.java but get the same result.
2.Using "javac *.java" goes well. However, if there have many files and only one file has been modified, I think recompiling all files will get low performance.
Originally posted by Rene Larsen:
Put a .(dot) in your CLASSPATH
Rene

I put a .(dot) in my CLASSPATH, but get same result.
 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My compile environment maybe go ill.
I use

also get the same result.
Can you tell me what's the problem?
 
Paulo Salgado
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you have the in your classes and the classpath set to
f:\javapackage, javac is probably trying to find your classes at f:\javapackage\javapackage.
Try to change you classpath to f:\ only or
remove the package statements from both classes to use the default package (the classes directory).
 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paulo Salgado:
Thanks!
I add ".\.." to my CLASSPATH. All go well.
Thanks William and Rene for your replies.
 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, there has another problem.
I have compiled the two files successfully. But I can not excute the aaa.class file.
After typing following command

I got the following error message.
---------- Run (java.exe) ----------
java.lang.NoClassDefFoundError: aaa (wrong name: javapackage/aaa)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
Exception in thread "main"
Output completed (0 sec consumed) - Normal Termination

Why can VM not find the class file?
Thanks!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make your working directory the parent directory of the package. So, try:
f:> java javapackage.aaa
What did you do to do to compile the files successfully?
 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
Make your working directory the parent directory of the package. So, try:
f:> java javapackage.aaa
What did you do to do to compile the files successfully?

Thanks!
I execute it successfully.
ps. I can't understand the question of you. Maybe the answer lies what I have posted above.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind. You already answered it. Thanks.
I add ".\.." to my CLASSPATH. All go well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic