gpt4 book ai didi

javafx-2 - javaFX 应用程序启动错误

转载 作者:行者123 更新时间:2023-12-02 21:46:08 25 4
gpt4 key购买 nike

我刚开始使用 javaFX,最近在通过 Eclipse 运行应用程序时遇到了以下错误。我的代码:

import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class WindowBetaV02 extends AbstractWindow{

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

public void start(Stage mainStage){
height = 480;
width = 640;
mainStage = new Stage();
mainStage.setTitle("AMQ");
mainStage.setScene(drawGUIGameNormal());
mainStage.setResizable(false);
mainStage.show();
}

private Scene drawGUIGameNormal(){
//Draw gui
}
}

import javafx.application.Application;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.stage.Stage;

public abstract class AbstractWindow extends Application {
protected int height;
protected int width;
protected GameFunctions controller;

public abstract void start(Stage stage);

protected GridPane createPlayerPane(int width, int height){
GridPane playerPane = createPixelGridPane(width, height);
playerPane.getStyleClass().add("playerPane");
playerPane.add(createPlayerTable(), 10, 10, width-10, width-10);
return playerPane;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
protected TableView createPlayerTable(){
TableView table = new TableView();
TableColumn points = new TableColumn("Points");
points.setMaxWidth(30);
points.setMinWidth(30);
points.setCellFactory(new PropertyValueFactory<Players, Integer>("points"));

TableColumn player = new TableColumn("Player");
player.setMaxWidth(100);
player.setMinWidth(100);
player.setCellFactory(new PropertyValueFactory<Players, String>("playerName"));

table.setItems(controller.getPlayers());
table.getColumns().addAll(player, points);

return table;
}

protected GridPane createPixelGridPane(int width, int height){
GridPane pane = new GridPane();
for(int i = 0; i < width; i++){
pane.getColumnConstraints().add(new ColumnConstraints(1));
}
for(int i = 0; i < height; i++){
pane.getRowConstraints().add(new RowConstraints(1));
}
return pane;
}
}

错误

Exception in thread "main" java.lang.RuntimeException: Application launch error
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:122)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: com.sun.glass.ui.win.WinApplication._invokeLater(Ljava/lang/Runnable;)V
at com.sun.glass.ui.win.WinApplication._invokeLater(Native Method)
at com.sun.glass.ui.Application.invokeLater(Application.java:338)
at com.sun.javafx.tk.quantum.QuantumToolkit.defer(QuantumToolkit.java:620)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:173)
at com.sun.javafx.application.PlatformImpl.runAndWait(PlatformImpl.java:212)
at com.sun.javafx.application.PlatformImpl.tkExit(PlatformImpl.java:320)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:421)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
... 1 more

有人知道如何修复这个错误吗?

-编辑-

添加了 AbstractWindow 类的代码

最佳答案

您在 JavaFx 中,您的 Main 类必须扩展 Application 而不是 Window

关于javafx-2 - javaFX 应用程序启动错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20196420/

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