bad class file error when it read class file .......
843810Jan 20 2009 — edited Jan 20 2009I 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.