[英]Yet another 'cannot find symbol' error when creating a new class object
In short, I'm trying to instantiate within the main method in order to handle computations. 简而言之,我试图在main方法中实例化以处理计算。 I wrote the main class in Eclipse and was able to compile and run everything smoothly.
我在Eclipse中编写了主类,并且能够顺利地编译和运行所有内容。
Main Method: 主要方法:
public static void main(String[] args)
{
...
OutsideClass class = new OutsideClass();
...
}
I ran it in eclipse, which worked smoothly until I got an error due to to insufficient privileges, which led me to switch over to using cmd.exe as an administrator. 我在eclipse中运行它,它运行顺利,直到我因为权限不足而出现错误,这导致我切换到使用cmd.exe作为管理员。
I navigated to the eclipse folder where I had all the classes saved to and ran javac x.java
for each file in the folder, one by one. 我导航到eclipse文件夹,我保存了所有类,然后
javac x.java
为文件夹中的每个文件运行javac x.java
。 I was able to do javac OutsideClass.java
without any errors, though when it came to javac Main.java
, I received the following error: 我能够做没有任何错误的
javac OutsideClass.java
,但是当涉及到javac Main.java
,我收到了以下错误:
Main.java:36: error: cannot find symbol
OutsideClass outside = new OutsideClass();
^
symbol: class OutsideClass
location: class Main
Main.java:36: error: cannot find symbol
OutsideClass outside = new OutsideClass();
^
symbol: class OutsideClass
location: class Main
2 errors
The OutsideClass
doesn't have a defined constructor, though I don't know if that really matters or not. OutsideClass
没有定义的构造函数,但我不知道这是否真的重要。
The Java compiler needs the source ( .java
) or bytecode ( .class
) of OutsideClass
when compiling Main.java
. 编译
Main.java
时,Java编译器需要OutsideClass
的源( .java
)或字节码( .class
)。
Try javac *.Java
, or javac -cp OutsideClass.class Main.java
to provide OutsideClass
's definition to the compiler when compiling Main
. 尝试使用
javac *.Java
或javac -cp OutsideClass.class Main.java
在编译Main
时为编译器提供OutsideClass
的定义。
It is more customary for Java developers to compile all Java sources of a single project via one javac
invitation, either directly, or via a tool such as Maven . 对于Java开发人员来说,通过一个
javac
邀请直接或通过Maven等工具编译单个项目的所有Java源代码更为习惯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.