【发布时间】:2014-11-18 03:31:43
【问题描述】:
我知道这个问题有很多重复,但我都看过了,都没有解决问题。
我正在尝试运行一个具有主要功能的类。我已经清理了项目,检查了“。”的类路径,将 bin 文件夹添加到运行配置下的类路径中。我不确定还能尝试什么,因为该类肯定在源文件夹中。
有人可以帮我解决这个问题吗?
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 文件。
这是错误: 错误:无法找到或加载主类 testIt.MemoryVisualizerApp
【问题讨论】:
-
您是右键单击具有
main()方法的类并单击“作为Java 应用程序运行”,还是右键单击项目?不过,在后者中,它应该使用main()方法建议所有类。 -
你的
main()方法是静态的吗? -
您是如何尝试运行我们的代码的?我们能看到它放在哪里以及它的样子吗?
-
@watery 是的,我尝试通过右键单击类并作为 java 应用程序运行来运行代码。是的,主要方法是静态的。添加了代码。
-
当您尝试运行程序时,我们能看到错误消息是什么吗?还有launch()函数?
标签: java eclipse classpath main