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!!!Please help me

843810Jul 14 2005 — edited Oct 10 2007
I got a problem that is very strange. I have two source files saved in the same directory: E:\Java Programmes

First one: A.java
package util;

public class A {
	public int add(int x, int y){
		return (x + y);
	}
}
Second one: B.java
import util.*;

public class B {
	public static void main(String args[]){
		A a = new A();
		System.out.println("Result: " + a.add(3, 5));
	}
}
I compiled these two files and got problem as follow:

*compiling file A.java is ok, no problem.
E:\Java Programmes>javac -d "E:\Java Programmes" A.java


*but got problem with B.java
E:\Java Programmes>javac B.java
B.java:5: cannot access A
bad class file: .\A.java
file does not contain class A
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
A a = new A();
^
1 error


*The strange thing is that when i modify the file B.java as follow, it can run well
import util.A;

public class B {
	public static void main(String args[]){
		A a = new A();
		System.out.println("Result: " + a.add(3, 5));
	}
}
Output = Result: 8.

I keep wondering why it is like that. Because the statement "import util;*; " does not work well while the statement import "util.A ; " can work well. Please, anyone, explain it to me. Thannks a lot.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 7 2007
Added on Jul 14 2005
9 comments
2,933 views