编译包含其他类类型对象的Java类时找不到符号错误 [英] cannot find symbol error while compiling a java class containing other class type object

查看:374
本文介绍了编译包含其他类类型对象的Java类时找不到符号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java包,其中包含两个类. A类和B类.我需要在B类中创建一个A类型的对象.我不知道发生了什么.请有人帮我.

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.

包装盒;

A类

B类

我正在使用JDK1.5和tomcat,并将它们放在D驱动器的java文件夹中.

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

下面是我编译Java类文件的方式.

Below is how i am compiling my java class files.

第1步:编译A.java

D:\ Java \ pack> 设置路径= D:\ java \ jdk1.5 \ bin (为jdk1.5编译器设置路径)

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

D:\ Java \ pack> javac A.java (成功编译并形成了 A.class )

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

第1步:编译B.java

D:\ Java \ pack> javac B.java (在这里,我收到一条错误消息)

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

下面是错误消息

错误消息

D:\ Java \ pack> javac B.java

B.java:9:找不到符号

符号:A类

位置:课程包.B

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

B.java:9:找不到符号

符号:A类

位置:课程包.B

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

2个错误

推荐答案

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

则对应于

pack\B.java

在目录结构中

这篇关于编译包含其他类类型对象的Java类时找不到符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆