Eclipse错误“找不到或加载主类” [英] Eclipse error "Could not find or load main class"

查看:241
本文介绍了Eclipse错误“找不到或加载主类”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题有很多重复,但是我已经看过他们,并没有人解决了这个问题。

I know there are many duplicates of this question, but I have looked at them all, and none of them have solved the issue.

我试图运行一个具有主要功能的类。我已经清理了项目,检查了类路径为'。',将bin文件夹添加到运行配置下的类路径中。我不知道还有什么可以尝试的,因为课程肯定是在源文件夹中。

I am trying to run a class that has a main function. I have cleaned the project, checked the classpath for '.', added the bin folder to the classpath under run configurations. I'm not sure what else to try because the class is certainly in the source folder.

有人可以帮我解决这个问题吗?

Could someone please help me with this issue?

package testIt;

public class MemoryVisualizerApp extends Application{

public static void main(String[] args) {
    launch(args);
}

//Setup the scene and launch with given properties
@Override
public void start(Stage primaryStage) throws IOException{
    Parent root = FXMLLoader.load(getClass().getResource("/MemoryVisualizer.fxml"));
    Scene scene = new Scene(root, 650, 300);
    //Set whether the screen should be re-sizable (possibly best size = default)
    primaryStage.setResizable(true);
    primaryStage.setMinHeight(300);
    primaryStage.setMinWidth(550);
    primaryStage.setTitle("Memory Usage");
    primaryStage.setScene(scene);
    scene.getStylesheets().add("testIt/MemoryVisualizer.css");
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() 
    {
        public void handle(WindowEvent e){
              /*Currently the threads continue running after window is closed. Looking for
              a way to stop the app threads when window closed without stopping the program.*/
        }
    });
    primaryStage.show();
    primaryStage.show();
}

}

此代码位于一个包中,使用src文件夹。它使用一些未显示的JavaFX文件,但不应该是一个问题。

This code is located within a package, withing the src folder. It utilizes some JavaFX files that arent shown but that shouldnt be an issue.

这是错误:
错误:找不到或加载主class testIt.MemoryVisualizerApp

推荐答案

如果您面临类似的问题,它与运行配置在Eclipse中无法正常工作。

If you are facing similar problem,it has to do with the "Run Configurations" not working properly in Eclipse.

请在您的java类中包含主要方法。转到运行方式 - >运行配置并放置正确的参数。项目应该是包含主类的项目,主类应该是符合条件的类名。请看下面的快照,以了解清楚。它应该是正常的。然而,您正在创建一个运行配置,您可以使用保存的配置以供以后使用。

Please right clik on your java class containing the main method .Go to Run As-> Run Configurations and put the correct patrameters.Project should be the Project which contains the main class and Main class should be fuly qualified class name.See the snapshots below for clarity.It should wok fine then.Basically,you are creating a Run configuration and you can use that saved configuration for later use also.

这篇关于Eclipse错误“找不到或加载主类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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