0

I have this directory structure:

project1/src/edu/course/firstweek/javacourse/Program1.java

Another file in one package above:

project1/src/edu/course/firstweek/program2.java

In the header of program2.java, I have

package edu.course.firstweek;

import edu.course.firstweek.javacourse.Program1;

Now to when I run the following in commandline:

Javac src/edu/course/firstweek/program2.java, I get this error:

src/edu/course/firstweek/program2.java:14:error cannot find symbol
      System.out.println(program1.print("hello world"));

   symbol:   variable Program1
   location: class program2
2 errors

I can see that the compiler is not able to find the program1,but I have the correct import package statement in program2. I need help here and after compiling, is there something that needs to be taken into account for running the program.

Thanks

1 Answer 1

0

Try going into one directory inside, i.e. cd src and then compile Javac edu/course/firstweek/program2.java

for running, do java edu.course.firstweek.program2

Sign up to request clarification or add additional context in comments.

3 Comments

huh! this worked, but why is that going into src made the difference?
Because it gives you an implicit CLASSPATH of '.', and '.' is now the top of your package hierarchy. You should always be there when compiling.
@EJP: what needs to be done to make it work if I have not done cd src that is I am not in '.' correct?

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.