• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Comilation Problem

 
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 ]
 
Sheriff
Posts: 9099
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?
 
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");
}
}
 
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
 
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.
 
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
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic