简体   繁体   English

在创建新的类对象时,另一个“找不到符号”错误

[英]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 *.Javajavac -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.

相关问题 从 class 创建新的 object 时出现“找不到符号”错误? - 'Cannot find symbol' Error when creating a new object from a class? 创建 object 时找不到符号错误 - Cannot Find Symbol Error when creating an object 创建新的字符串数组时类型不兼容,访问另一个类变量时找不到符号 - Incompatible types when creating new string array and cannot find symbol when accessing another class variable 在新的 class 中创建方法; 在主 class 中找不到符号错误 - creating method in new class; cannot find symbol error in main class 使用继承在IO类中创建对象时找不到符号 - Cannot find symbol when creating an object in IO class using inheritance 创建对象实例时出现“找不到符号”错误 - "Cannot find symbol" error when creating an instance of an object 创建对象时如何解决“错误:找不到符号”? - How to fix “Error: Cannot find symbol” when creating an object? 在java中创建另一个类的对象时找不到符号错误而只在windows中扩展 - cannot find symbol error when create object of another class in java without extends only in windows 声明新的午餐包对象时出现“错误:找不到符号”? - 'error: cannot find symbol' when declaring a new lunchBag object? 创建对象并调用方法时出错,错误:找不到符号 - Error creating an object and calling a method, error: cannot find symbol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM