Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

bad class file error when it read class file .......

843810Jan 20 2009 — edited Jan 20 2009
I got some very interesting problems....

I've got two source files:

Hello.java, Use.java

Hello.java:

package pack;
public class Hello
{
public static void fun(String[] args)
{
System.out.println("Hello World!");
}
}

Use.java:

class Use
{
public static void main(String[] args)
{
Hello.fun();
}
}

I compiled Hello.java using the command : javac -d . Hello.java
it worked well and I got the class file in the folder "pack" in the working directory.

In the working directory, I have Use.java, the folder "pack" that contains Hello.class and a folder "source" that contains "Hello.java".

when I try to compile Use.java, I get the following error:

Use.java:5: cannot find symbol
symbol : variable Hello
location: class Use
Hello.fun();
^
1 error

To clear this, I tried to use CLASSPATH environment variable to point to Hello.class that is present in the folder "pack".

to the existing CLASSPATH value of

D:\Program Files\Java\jre1.5.0_16\lib\rt.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;.;D:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar

I added C:\pack by the following command:

set CLASSPATH=%CLASSPATH%;C:\pack

And then again I tried to compile Use.java without providing the import statement as

javac use.java

and I got the following error:

Use.java:5: cannot access Hello
bad class file: C:\pack\Hello.class
class file contains wrong class: pack.Hello
Please remove or make sure it appears in the correct subdirectory of the classpath.
Hello.fun();
^
1 error

Can anyone please help me out with this.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2009
Added on Jan 20 2009
6 comments
6,563 views