Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comilation Problem

 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a very small problem. I have 2 classes as follows

How can i solve this.

(Marilyn added code tags)
[ July 04, 2004: Message edited by: Marilyn de Queiroz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are A.class and B.class in the same directory? Is that directory in your classpath?
 
Vi David
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class A{
public static void main(String args[]){
System.out.println("hello");
B obj = new B();
obj.method();
}
}
class B{
public void method(){
System.out.println("Inside this method");
}
}
 
Jos� Alberto Mu�iz Navarro
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really a solution but a workaround Have you tried not making B public and typing it in the same file as the other one? I know that would solve it, but it would depend on how you want to access B
 
Gary Down
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you compiled the 'B'?

when you comple "a" it will need "b" to be compled already.

Just a thought.
Gary.
 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both these files are in same directory. And i want these files in two different files as A.java and B.java
I believe classpath setting i have done.
 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i have compiled the B.java file before compiling A.java file. After that this error has occurerd. If possible please try compiling these two files.
 
Jeff Pavlocak
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
satya,

Your code looked good to me, so I copied your code from the top thread and compiled it. The code compiled fine and ran fine.

Double check that your code matches exactly what is in the thread and you should be good. Or better yet, do what I did and copy it from the thread and paste it into your text editor.

Remember Java is case sensitive.

Also, you don't need to compile the B.java file before the A.java file. The compiler will take care of that for you.

Good luck,

Jeff Pavlocak
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic