cannot find symbol error while compiling a java class containing other class type object

£可爱£侵袭症+ 提交于 2020-01-17 01:36:32

问题


I have a java package which contains two classes. Class A and Class B. I need to create an object of A type in class B. I don't know what is happening. Please someone help me out.

package pack;

class A

class B

I'm using JDK1.5 and tomcat and placed them in java folder in my D drive.

D:\java\jdk1.5

D:\java\tomcat

Right now, my package folder is also in above location

D:\java\pack

Below is how i am compiling my java class files.

Step 1: Compiling A.java

D:\Java\pack>set path=D:\java\jdk1.5\bin (setting up path for jdk1.5 compiler)

D:\Java\pack>javac A.java (Successfuly compiled and formed A.class)

Step 1: Compiling B.java

D:\Java\pack>javac B.java (here, i get an error message )

Below is the ERROR message

Error Message

D:\Java\pack>javac B.java

B.java:9: cannot find symbol

symbol : class A

location: class pack.B

            A a = new A();    //creating an object of A type
            ^

B.java:9: cannot find symbol

symbol : class A

location: class pack.B

            A a = new A();      //creating an object of A type
                      ^

2 errors


回答1:


javac pack\A.java pack\B.java

will do the trick. The compiler has to be able to resolve everything in one invocation. If it's looking for

pack.B

then that corresponds to

pack\B.java

in the directory structure



来源:https://stackoverflow.com/questions/13472319/cannot-find-symbol-error-while-compiling-a-java-class-containing-other-class-typ

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!