• Post Reply Bookmark Topic Watch Topic
  • New Topic

B.java:7: cannot access A--bad class file: .\A.java  RSS feed

 
Narasimha Raju Naidu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Saikiran Vadlakonda
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mr.Narasimha Raju Naidu

i too got this error.
for this i did one thing that is simply i had cut and pasted those .java files into the package which are created by JVM.
paste your .java files into the packages.

do like this
pan
dawn
A.java
okay
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!