getting error when I compile the Java code using p

2019-01-29 12:49发布

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条回答
Evening l夕情丶
2楼-- · 2019-01-29 13:43

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

查看更多
登录 后发表回答