2

I have two classes Hello1 and Hello, and I'm calling class Hello1 constructor within Hello class, but when I trying to compile the Hello class with command

javac Hello.java

I'm getting compile time error:

Hello.java:6:cannot find the symbol
symbol: class Hello1
location: class Hello
Hello1=new Hello();
^
Hello.java:6:cannot find the symbol
symbol: class Hello1
location: class Hello
Hello1=new Hello();
           ^

But when I try to compile the compile the class with command:

javac Hello.java Hello1.java

it's working fine, but why I have to use this command every time to compile the class? Why the compiler can't use the already compiled .class Hello1 file, so that next time I use the command javac Hello.java.

3
  • Have you tried passing the classpath of the compiled Hello1 class to the compiler? Commented Oct 14, 2009 at 17:30
  • The line with errors looks very weird in your example : Hello1 is supposed to be a class no? Please check Commented Oct 14, 2009 at 17:32
  • Thanks! Now I understood what's wrong I was doing. Commented Oct 14, 2009 at 17:32

2 Answers 2

1

You need to add the current directory to your classpath so the compiler can find it. By default, the classpath does not include the current working directory, so any .class files which have already been compiled won't be seen by the compiler. To do this, compile like this:

javac Hello.java -cp .
Sign up to request clarification or add additional context in comments.

Comments

1

You need to set the classPath with -cp .

1 Comment

Posting from an iPhone is not the fastest way to answer a question :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.