- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当我单击“开始按钮”时出现错误,它加载了一个新的 fxml,我将在其中玩它,它工作正常,但控制台告诉我这个错误。我无法理解如何解决它。
我的 FXML:(只看 startGame,这给我带来了一些问题)
public class StartImageController implements Initializable {
@FXML
private MenuBar myMenuBar;
private AudioClip audio;
private AudioClip beep;
@Override
public void initialize(URL url, ResourceBundle rb) {
audio = new AudioClip(getClass().getClassLoader().getResource("othello/music/background_music.wav").toExternalForm());
beep = new AudioClip(getClass().getClassLoader().getResource("othello/music/button.wav").toExternalForm());
audio.stop();
audio.setVolume(0.2);
audio.setCycleCount(INDEFINITE);
audio.play();
}
//Metodo per chiudere l'intero programma
@FXML
private void exitProgram(ActionEvent event) {
System.exit(0);
}
//Metodo per chiudere solo lo stage
private void exitStage(ActionEvent event){
((Node)(event.getSource())).getScene().getWindow().hide();
}
//Metodo per far partire la musica da menu item
@FXML
public void audioY(ActionEvent e)throws IOException{
audio.stop();
audio.setVolume(0.2);
audio.setCycleCount(INDEFINITE);
audio.play();
}
//Metodo per togliere la musica da menu item
@FXML
public void audioN(ActionEvent e)throws IOException{
audio.stop();
}
//Metodo per tema dark
@FXML
public void darkTheme(ActionEvent event) throws IOException {
//fermo la canzone del tema light e avvio la canzone del tema dark
audio.stop();
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("othello/view/startImageDark.fxml"));
Scene scene = new Scene(root);
Stage stage = (Stage) myMenuBar.getScene().getWindow();
stage.setScene(scene);
stage.show();
}
//Metodo per far partire la sessione di gioco
@FXML
public void startGame(ActionEvent event) throws IOException {
beep.play();
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("othello/view/board.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("othello/view/lightTheme.css");
//la scena entra in fade
FadeTransition ft = new FadeTransition(Duration.millis(3000), root);
ft.setFromValue(0.0);
ft.setToValue(1.0);
ft.play();
Node node=(Node) event.getSource();
Stage stage=(Stage) node.getScene().getWindow();
audio.stop();
stage.setResizable(false);
stage.setTitle("Othello - Game session");
stage.setScene(scene);
stage.show();
}
//Metodo per visualizzare le istruzioni da menu item
@FXML
public void showInstruction(ActionEvent event) throws IOException {
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("othello/view/instruction.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.sizeToScene();
primaryStage.setTitle("Instruction");
primaryStage.show();
}
//Metodo per visualizzare about da menu item
@FXML
public void showAbout(ActionEvent event) throws IOException {
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("othello/view/about.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("othello/view/about.css");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.sizeToScene();
primaryStage.setTitle("About");
primaryStage.show();
}
//Metodo per visualizzare il background del team da menu item in formato HTML
@FXML
public void showBackground(ActionEvent event) throws IOException {
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("othello/view/teamBackground.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("othello/view/teamBackground.css");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.sizeToScene();
primaryStage.setTitle("Team Background");
primaryStage.show();
}
}
我的看板 FXML
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="460.0" prefWidth="600.0" styleClass="root" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="othello.controller.BoardController">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="Game">
<items>
<MenuItem mnemonicParsing="false" onAction="#cleanStart" text="New Game" />
<MenuItem mnemonicParsing="false" onAction="#restartGame" text="Restart" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#helpMe" text="Next move" />
<SeparatorMenuItem mnemonicParsing="false" />
<Menu mnemonicParsing="false" text="Music">
<items>
<MenuItem mnemonicParsing="false" onAction="#audioY" text="On" />
<MenuItem mnemonicParsing="false" onAction="#audioN" text="Off" />
</items>
</Menu>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#exitProgram" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#playRules2" text="How to play" />
<MenuItem mnemonicParsing="false" onAction="#showAbout" text="About" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Project">
<items>
<MenuItem mnemonicParsing="false" onAction="#showBackground" text="Team Background" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Log Match">
<items>
<MenuItem mnemonicParsing="false" onAction="#openLog" text="Last 10 matches.." />
</items>
</Menu>
</menus>
</MenuBar>
<SplitPane dividerPositions="0.6833333333333333" styleClass="root">
<items>
<AnchorPane maxWidth="410.0" minHeight="0.0" minWidth="-Infinity">
<children>
<GridPane fx:id="myGrid" alignment="CENTER" gridLinesVisible="true" layoutX="3.0" layoutY="5.0" prefHeight="400.0" prefWidth="400.0" styleClass="scacchiera">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
<children>
<ImageView fx:id="imageView00" fitHeight="48.0" fitWidth="48.0" onMouseClicked="#handleOnMouseClicked" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="imageView01" fitHeight="48.0" fitWidth="48.0" onMouseClicked="#handleOnMouseClicked" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" />
<ImageView fx:id="imageView02" fitHeight="48.0" fitWidth="48.0" onMouseClicked="#handleOnMouseClicked" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="2" />
</children>
</GridPane>
</children>
</AnchorPane>
<AnchorPane SplitPane.resizableWithParent="false">
<padding>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</padding>
<children>
<Button layoutX="115.0" layoutY="369.0" mnemonicParsing="false" onAction="#restartGame" text="Restart" textAlignment="CENTER" />
<TextField fx:id="txt_field_p1" layoutX="9.0" layoutY="36.0" promptText="Insert name.." />
<TextField fx:id="txt_field_p2" layoutX="9.0" layoutY="90.0" promptText="Insert name..." />
<Label layoutX="7.0" layoutY="14.0" styleClass="text" text="Player 1 name:" textFill="WHITE" />
<Label layoutX="7.0" layoutY="70.0" styleClass="text" text="Player 2 name:" textFill="WHITE" />
<Label layoutX="43.0" layoutY="151.0" styleClass="text" text="Choose color:" textFill="WHITE" />
<Label layoutX="10.0" layoutY="171.0" styleClass="text" text="P1" textFill="WHITE" />
<Label layoutX="100.0" layoutY="172.0" styleClass="text" text="P2" textFill="WHITE" />
<RadioButton fx:id="rd_p1_black" layoutX="46.0" layoutY="193.0" mnemonicParsing="false" onAction="#chooseColor" prefHeight="0.0" prefWidth="0.0">
<toggleGroup>
<ToggleGroup fx:id="group_p1" />
</toggleGroup></RadioButton>
<RadioButton fx:id="rd_p2_black" layoutX="134.0" layoutY="193.0" mnemonicParsing="false" onAction="#chooseColor" prefHeight="0.0" prefWidth="0.0">
<toggleGroup>
<ToggleGroup fx:id="group_p2" />
</toggleGroup></RadioButton>
<ImageView fitHeight="35.0" fitWidth="32.0" layoutX="11.0" layoutY="186.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/black.png" />
</image>
</ImageView>
<ImageView fitHeight="35.0" fitWidth="32.0" layoutX="11.0" layoutY="218.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/white.png" />
</image>
</ImageView>
<RadioButton fx:id="rd_p1_white" layoutX="46.0" layoutY="225.0" mnemonicParsing="false" onAction="#chooseColor" prefHeight="0.0" prefWidth="0.0" toggleGroup="$group_p1" />
<ImageView fitHeight="35.0" fitWidth="32.0" layoutX="101.0" layoutY="186.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/black.png" />
</image>
</ImageView>
<ImageView fitHeight="35.0" fitWidth="32.0" layoutX="101.0" layoutY="218.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/white.png" />
</image>
</ImageView>
<RadioButton fx:id="rd_p2_white" layoutX="134.0" layoutY="225.0" mnemonicParsing="false" onAction="#chooseColor" prefHeight="0.0" prefWidth="0.0" toggleGroup="$group_p2" />
<Label layoutX="67.0" layoutY="270.0" styleClass="text" text="Score:" textFill="WHITE" />
<Label layoutX="10.0" layoutY="298.0" styleClass="text" text="P1" textFill="WHITE" />
<Label layoutX="100.0" layoutY="298.0" styleClass="text" text="P2" textFill="WHITE" />
<Label fx:id="p1_totScore" layoutX="33.0" layoutY="312.0" styleClass="text" text="0" textFill="#d9dd96">
<font>
<Font size="36.0" />
</font>
</Label>
<Label fx:id="p2_totScore" layoutX="126.0" layoutY="313.0" styleClass="text" text="0" textFill="#d9dd96">
<font>
<Font size="36.0" />
</font>
</Label>
<Button fx:id="btn_start" layoutX="61.0" layoutY="369.0" mnemonicParsing="false" onAction="#newGame" text="Start" textAlignment="CENTER" />
<Button fx:id="btn_pass" layoutX="11.0" layoutY="369.0" mnemonicParsing="false" onAction="#passRound" text="Pass" />
</children>
</AnchorPane>
</items>
<padding>
<Insets bottom="4.0" />
</padding>
</SplitPane>
<GridPane prefHeight="20.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="20.0" minWidth="0.0" prefWidth="0.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="30.0" minWidth="0.0" prefWidth="30.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="2.0" prefWidth="2.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" maxWidth="30.0" minWidth="0.0" prefWidth="30.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="20.0" minWidth="0.0" prefWidth="0.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints />
<RowConstraints />
</rowConstraints>
<children>
<ImageView fx:id="imgCount_p1" fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="LEFT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<image>
<Image url="@../images/black.png" />
</image>
</ImageView>
<ImageView fx:id="imgCount_p2" fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="5" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<image>
<Image url="@../images/white.png" />
</image>
</ImageView>
<Label fx:id="label_count_p1" styleClass="text" text="0" textFill="WHITE" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<Label fx:id="label_count_p2" alignment="CENTER_RIGHT" styleClass="text" text="0" textFill="WHITE" GridPane.columnIndex="4" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<Label fx:id="label_output" alignment="CENTER_RIGHT" contentDisplay="CENTER" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="300.0" styleClass="text" text="Black starts moving" textAlignment="CENTER" textFill="#f6ff00" GridPane.columnIndex="2" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<Label fx:id="label_coord" alignment="CENTER_RIGHT" contentDisplay="CENTER" maxWidth="-Infinity" minWidth="-Infinity" prefHeight="18.0" prefWidth="228.0" styleClass="text" text="0:0" textAlignment="CENTER" textFill="#f6ff00" GridPane.columnIndex="3" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
</children>
</GridPane>
<ImageView fitHeight="48.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true" />
</children>
</VBox>
这里是今天更新的错误堆栈跟踪!当我点击开始按钮(改变场景)时,出现这个错误。
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.scene.control.skin.MenuBarSkin.lambda$new$383(MenuBarSkin.java:304)
at javafx.event.WeakEventHandler.handle(WeakEventHandler.java:79)
at com.sun.javafx.event.CompositeEventHandler$WeakEventFilterRecord.handleCapturingEvent(CompositeEventHandler.java:312)
at com.sun.javafx.event.CompositeEventHandler.dispatchCapturingEvent(CompositeEventHandler.java:98)
at com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:223)
at com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:180)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchCapturingEvent(CompositeEventDispatcher.java:43)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:52)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:745)
最佳答案
我不认为这与 FXML 有任何关系,因为我有一个应用程序抛出相同的异常,但我没有使用任何 FXML。当我添加功能以在我的应用程序的主要 Stage 上更改为新的 Scene 时,我的应用程序开始执行此操作。这些阶段的根 Parent 是 BorderPane,其中 MenuBar 节点设置为“顶部”节点。
我为防止这种情况所做的解决方法(并且它似乎运作良好)是从之前的 Scene 中的 BorderPane 中清除“顶部”节点设置新场景。我添加了一个在设置新场景之前调用的方法(需要保存对 Application.start(Stage) 提供的“舞台”的引用):
private void clearBorderPane() {
if ((stage != null) && (stage.getRoot() instanceof BorderPane)) {
BorderPane pane = (BorderPane)stage.getRoot();
pane.setTop(null);
}
}
似乎是将菜单与父布局解除关联,但我可能弄错了。
当然,这仅适用于我的应用程序和在 BorderPane 顶部有一个 MenuBar 的类似应用程序。对于其他类型的根 Pane ,可能值得从任何类型的 Pane 的子节点列表中删除 MenuBar 它被用作场景的根。
关于java.lang.NullPointerException 它有效,但错误。试图找出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45999518/
我正在将我的模板代码移植到 XTend。在某些时候,我在测试用例中有这种类型的条件处理: @Test def xtendIfTest() { val obj = new FD if (
我是新来的 kotlin , 当我开始 Null Safety 时,我对下面的情况感到困惑. There's some data inconsistency with regard to initia
我的应用程序一直在各种Android版本中保持良好状态。我有用户在Android 4.3、5.0、5.1和6.0上正常运行。但是,具有S7 Edge的用户刚刚更新了Android 7.0,将文本粘贴到
我使用的是最新版本的 LWUIT (1.5)。我在资源编辑器中设计了我的表单,然后将代码生成到 netbeans。问题是如果我想访问除表单之外的任何对象,我会收到此错误: java.lang.Null
更新: 我在 Fedora 21 上运行它。 SonarQube - 5.0。 SonarQube Runner - 2.4 更新 2:Findbugs v3.1,Java 插件 v2.8 更新3:
RecupData 我的类仅在 web 中返回 NullPointerException。我连接到 pgsql db 8.3.7 - 该脚本在“控制台”syso 中运行良好 - 但引发了测试 Web
我在 mac 上使用 Processing 2.08。我正在尝试使用文档中给出的 createShape 函数创建 PShape。 PShape s; void setup(){ size(500
我在 mac 上使用 Processing 2.08。我正在尝试使用文档中给出的 createShape 函数创建 PShape。 PShape s; void setup(){ size(500
每次运行此 jsp 时,都会收到以下错误异常: org.apache.jasper.JasperException: java.lang.NullPointerException root cause
Kotlin 在编译时有一个出色的 null 检查,使用分离到“可空?”和“不可为空”的对象。它有一个 KAnnotator 来帮助确定来自 Java 的对象是否可以为空。但是,如果 not-null
我有一个布局将显示一个TextView,用于显示一个滴答时间。我遵循了此链接中的代码 How to Display current time that changes dynamically for
Elasticsearch 1.4.1版(“lucene_version”:“4.10.2”) 我有一个像这样的文件: $ curl 'http://localhost:9200/blog/artic
这是我从另一个类调用函数的方法Selenium 设置已定义。 public void Transfer() throws Exception { System.out.println("\nTrans
我试图在主类中使用我在此类中创建的函数,但它崩溃并显示“警告:无法在根 0 处打开/创建首选项根节点 Software\JavaSoft\Prefsx80000002。 Windows RegCrea
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 3 年前。 我有一个 Java 代码,它将
我声明了两张牌: Card card1 = new Card('3', Card.Suit.clubs); Card card2 = new Card('T', Card.Suit.diamonds)
我编写了一段代码来解码 Base64 图像并在 javafx 中表示该图像。在我的 url base64 代码中不断变化。这就是我在 javafx 代码中使用任务的原因。但我收到错误:java.lan
我正在尝试使用 arrayList 的 arrayList 在 Java 中实现图形。 每当调用 addEdge 函数时,我都会收到 NullPointerException 。我似乎无法弄清楚为什么
我是 Java/android 的新手,所以很多这些术语都是外国的,但我愿意学习。我不打算详细介绍该应用程序,因为我认为它不相关。我目前的问题是,我使用了博客中的教程和代码 fragment ,并使我
我正在开发一个 Android 应用程序来在 Android developer guide 的帮助下录制视频.我程序上的所有代码都与此页面相同。 我在 之外定义了权限标签。 当应
我是一名优秀的程序员,十分优秀!