gpt4 book ai didi

java - ch14Eamples.MultipleStageDemo.main 处 Unresolved 编译(MultipleStageDemo.java :24)

转载 作者:行者123 更新时间:2023-12-01 11:00:47 25 4
gpt4 key购买 nike

我使用的是 Eclipse EE,但当我尝试导入 javafx.application.Application 时它会显示错误,因此我切换到 Eclipse SDK 版本。现在导入没有错误,但无法编译。

我正在按照我的 Java 书中的最新教程进行操作,因此我不知道为什么会发生错误。

这是我的代码:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class MultipleStageDemo extends Application{

@Override //Override the start method in the application class

public void start(Stage primaryStage) {
//Create a scene and place a button in the scene
Scene scene = new Scene(new Button("OK"), 200, 250);
primaryStage.setTitle("MyJavaFx"); //set the stage title
primaryStage.setScene(scene); //Place the scene in the stage
primaryStage.show(); //display the stage


Stage stage = new Stage(); //create 2nd stage
stage.setTitle("Second Stage");
stage.setScene(new Scene(new Button("New Stage"), 100, 100));
stage.show();
}

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

}

这是我的错误:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.Error: Unresolved compilation problem:
at ch14Eamples.MultipleStageDemo.main(MultipleStageDemo.java:24)
... 11 more
Exception running application ch14Eamples.MultipleStageDemo

最佳答案

运行时的输出表明真正的问题是您的代码未编译。在 Eclipse 中,您将看到问题的各种红色指示符,并且当您尝试运行时,它会弹出一个确认对话框,警告您该项目未编译。

Caused by: java.lang.Error: Unresolved compilation problem: 
at ch14Eamples.MultipleStageDemo.main(MultipleStageDemo.java:24)

在方法 main() 中,您将在 MultipleStageDemo.java 文件的第 24 行找到编译错误。在 Eclipse 的问题 View 中查看完整的编译错误消息。我的猜测是它找不到类 Application,并且您可能也有 Unresolved 导入错误。这意味着您的项目的类路径不完整,因为它缺少您需要的库。由于我没有使用过 javafx,所以我不知道这些库是什么或者在哪里可以找到它们。

关于java - ch14Eamples.MultipleStageDemo.main 处 Unresolved 编译(MultipleStageDemo.java :24),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33348783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com