| Author |
B.java:7: cannot access A--bad class file: .\A.java
|
Narasimha Raju Naidu
Ranch Hand
Joined: Mar 23, 2007
Posts: 37
|
|
hi to all, i am facing the following error while accessing methods of another class. Error
B.java:7: 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
my program code
i compiled A.java with the 'javac -d . A.java and B.java with javac B.java
While compiling B.java i am getting the above error. Please can any one tell how to resolve my problem. Waiting for your valuable replys. Regards, Narasimha Raju.Naidu
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
|
|
Not certain, but it sounds as though your file and directory structure might not be quite right. You might not have the naming of the A and B files quite right, too. Try compiling A first with the -d tag: javac -d . A.java then javac -d . B.java or both together javac -d . A.java B.java That might help.
|
 |
Narasimha Raju Naidu
Ranch Hand
Joined: Mar 23, 2007
Posts: 37
|
|
Thanks for your valuable reply. right now i am not in front of my system. i will. if it suceeded then how to compile my program B.java regards,
|
 |
Narasimha Raju Naidu
Ranch Hand
Joined: Mar 23, 2007
Posts: 37
|
|
hi friends, Still i am getting the same error. can any one resolve Regards [ April 16, 2008: Message edited by: Narasimha Raju Naidu ]
|
 |
Parthiban Malayandi
Ranch Hand
Joined: Apr 15, 2008
Posts: 67
|
|
Hi Narasimha, Did your java file "A" is inside a correct package structure? It should be in a directory called "dawn" which itself a subdirectory to "pan" (i.e) "A" file should be in pan\dawn\A.java The java file "B" should be outside to "pan" directory Put your files like that way and try it
|
 |
Ninad Sabnis
Greenhorn
Joined: Jan 09, 2011
Posts: 1
|
|
Hi,
I think the given error is because of * placed after package name.[packagename.*;].
If you place a particular class name insted of *, it compiles successfully.
Reason is , when we use -d option, it moves only .class file to the package hierarchy but leaves .java file at original location.
So because we are using *, compiler dont know the class to use at starting, and thus looks for required class file in current directory insted of package. In current directory it gets .java file for that class, so it skips searching and compiles .java [ hope without -d option] and place the .class file at current directory [without creation of hierarchy] which is not reght as we have decleared package in source file.
To overcome this problem we either need to move .java file to same package hierarchy created after compilation of it using -d option,
or move to other location / delete the source file after compiling it using -d option.
If anyone have more useful way to deal with this, please do post.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Ninad Sabnis wrote:
If anyone have more useful way to deal with this, please do post.
Since this topic is more than a year old, I think it is safe to assume that the OP has figured out how to compile a program by now. And BTW, welcome to the Ranch.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: B.java:7: cannot access A--bad class file: .\A.java
|
|
|