- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我有代码
import javax.swing.JOptionPane;
import javafx.application.Application;
public abstract class HHGUI extends Application {
JOptionPane yesno = new JOptionPane();
public HHGUI() {
int reply = JOptionPane.showConfirmDialog(null,"Do you want the ground to generate from premade file?","Read Ground From File", JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
Manager.plateaucreator();
System.exit(0);
}
else {
Manager.randplateaucreator();
System.exit(0);
}
}
public static void main(String[] args) {
launch(args);
}
}
我一直收到错误
Exception in Application constructor
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:873)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class HHGUI
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$7(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
... 1 more
Exception running application HHGUI
而且我已经查看了其他问题,但找不到导致此错误的任何遗漏。我已经阅读了 JOptionPanes,但我仍然不熟悉它们,所以帮助解决这个错误或帮助找出导致它的原因将不胜感激。
最佳答案
您不能调用抽象类。移除 abstract
修饰符并实现 start
方法:
import javax.swing.JOptionPane;
import javafx.application.Application;
import javafx.stage.Stage;
public class HHGUI extends Application {
JOptionPane yesno = new JOptionPane();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
int reply = JOptionPane.showConfirmDialog(null,"Do you want the ground to generate from premade file?","Read Ground From File", JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
System.out.println("Yes");
System.exit(0);
}
else {
System.out.println("NO");
System.exit(0);
}
}
}
虽然可以使用 swing JOptionPane
,但在 JavaFx 中应该使用 Alert
控件:
import java.util.Optional;
import javafx.application.Application;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;
public class HHGUI extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Alert yesNo = new Alert(AlertType.CONFIRMATION,
"Do you want the ground to generate from premade file?",
ButtonType.YES,
ButtonType.NO);
yesNo.setTitle("Read Ground From File");
Optional<ButtonType> result = yesNo.showAndWait();
if (result.get() == ButtonType.OK) {
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}
关于java - JOptionPane YES_NO_OPTION 不理解异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64905512/
我在使用一个非常基础的初级 Java 程序时遇到了一些问题。我有一个函数,它应该根据用户对 JOptionPane YES_NO_OPTION 消息框的响应返回一个值。该程序运行良好,直到您看到重新开
所以我有代码 import javax.swing.JOptionPane; import javafx.application.Application; public abstract class
这是我的问题,我试图让这段代码正常工作,以便在我的 GUI 中,当我单击"is"时,会添加产品(该段代码仍有待开发)并且 addproductwindow 关闭,但当单击 no 时,JOptionPa
开发一个 swing 应用程序,如果用户单击 JoptionPane.showConfirmDialog 上的 No 按钮,我需要将用户重定向到另一个 JFrame。我写了这段代码: private
我编写了一个程序来识别字符串的平方、平方根、数字的立方和反转,但我有一些错误,我不知道如何解决这个问题。 下面是我的代码 import javax.swing.JOptionPane;
是否有人有创建 JOptionPane(例如 YES_NO_OPTION 对话框)并将默认值更改为“NO”同时保留键盘快捷键的经验?我使用对象数组来填充 {"YES", "NO"} 的选项,然后在 J
基本上,我有一个游戏,当发生某些事情时会调出 JOptionPane,我希望能够在用户单击"is"时返回游戏。有点像取消暂停功能 最佳答案 注意:当我发布这个答案时,问题完全不同 - 请阅读评论。 由
我在四个单独的对话框中有一系列四个是/否选择,其累积结果将导致十二个单独链接之一(例如,是/是/是/否 -> 链接 A,是/否/否/是 -> 链接 B,等等)。分支逻辑使用 boolean 值。 这是
我是一名优秀的程序员,十分优秀!