gpt4 book ai didi

java - 运行 javafx 11 程序时出现 InspirationTargetException

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

当我将代码复制并粘贴到几周前创建的另一个 javafx 程序中时,我的代码得以运行,但由于某种原因,每当我创建新的 javafx 程序时,我都无法让它们运行并获取这些程序错误:

Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.scene.control.ControlHelper (in unnamed module @0xb69df6e) cannot access class com.sun.javafx.scene.layout.RegionHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene.layout to unnamed module @0xb69df6e
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at javafx.scene.control.Control.<clinit>(Control.java:86)
at Homework4.Homework4.start(Homework4.java:24)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application Homework4.Homework4

我认为我的 JDK11/JavaFX11 有问题,不允许我创建更多 JavaFX 项目,因为某些原因使每个新项目都有此编译错误。我认为该错误是由于 java.lang.IllegalAccessError 造成的,但我不知道如何修复它。

这是我的引用代码:

package Homework4;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


public class Homework4 extends Application {

private TextField firstNum;
private TextField secondNum;
private Button plus;
private Button equals;
private TextField result;

@Override
public void start(Stage stage) {
firstNum = new TextField();
firstNum.setMaxWidth(100);
firstNum.setOnAction(event -> handleEquals(event));

secondNum = new TextField();
secondNum.setMaxWidth(100);
secondNum.setOnAction(event -> handleEquals(event));

plus = new Button("+");
plus.setOnAction(event -> handleEquals(event));

equals = new Button("=");
equals.setOnAction(event -> handleEquals(event));

result = new TextField();
result.setEditable(false);

HBox innerPane = new HBox();
innerPane.setSpacing(10);
innerPane.setPadding(new Insets(10, 10, 10, 10));
innerPane.getChildren().addAll(firstNum, plus, secondNum, equals);

VBox pane = new VBox();
pane.setPadding(new Insets(10, 10, 10, 10));
pane.getChildren().addAll(innerPane, result);

stage.setScene(new Scene(pane));
stage.setTitle("Welcome to Calculator 3000!");
stage.show();

}

private void handleEquals(ActionEvent event){
if(!(firstNum.getText().equals("") || secondNum.getText().equals(""))){
result.setText(firstNum.getText() + secondNum.getText());
}
}

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

}

我目前正在使用最新更新的 IntelliJ Idea 进行编码。

旁注,我目前是大学新生,刚刚开始创建 javafx 项目,因此欢迎任何帮助/建议!

我试图查看此线程以寻求帮助:InvocationTargetException when running a javafx program

不幸的是,我没有编码知识来理解人们在此线程中发布的建议。

最佳答案

事实证明,我没有正确设置 IntelliJ,这导致了我的 InitationTargetException。假设您的所有环境变量均正确,请遵循这些 instructions可能修复异常。

关于java - 运行 javafx 11 程序时出现 InspirationTargetException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54014863/

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