Heho社区, 当我在eclipse中运行它时,我创建了一个JavaFx应用程序并且每个工作都很好。但是当我将应用程序作为jar文件运行时,我得到以下错误。几天前,我有另一个控制器问题(可以解决)和一个“隐藏”的invocationTargetException,当出现另一个错误时,它出现在Eclipse的控制台中。我无法解决这个问题,我猜运行jar时出现的错误就是指。这是我的旧问题的链接:JavaFX Exception in Application constructor java.lang.reflect.InvocationTargetException
运行jar时的当前错误:
java.lang.NullPointerException
at application.Main.start(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
这是我的主要:
package application;
import java.io.IOException;
import application.view.ControllerSpielanleitung;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.DepthTest;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
//anLeitungLaden();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("resources/Layout.fxml"));
Pane pane = (Pane) loader.load();
Scene scene = new Scene(pane);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setTitle("Hashiwokakero");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.getIcons().add(new Image(Main.class.getResource("resources/Alien.png").toString()));
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
};
和Layout.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.paint.*?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<Pane id="root" fx:id="root" prefHeight="839.0" prefWidth="1281.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.view.Controller">
<children>
<Pane id="pane" fx:id="pane" layoutX="21.0" layoutY="64.0"
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="749.0" prefWidth="1209.0"
style="-fx-border-radius: 100; -fx-border-width: 100;">
<children>
<Button id="newLevelButton" fx:id="newLevelButton" layoutX="363.0"
layoutY="303.0" mnemonicParsing="false" onAction="#handleNewLevelButton"
prefHeight="66.0" prefWidth="484.0"
style="-fx-border-color: #ffd308; -fx-border-radius: 30;" text="Weiter zu Level 2"
textFill="#ffd308">
<font>
<Font name="Franklin Gothic Medium Cond" size="40.0" />
</font>
</Button>
<Button id="hintButton" fx:id="hintButton" layoutX="1042.0"
layoutY="685.0" mnemonicParsing="false" onAction="#handleHintButton"
prefHeight="41.0" prefWidth="153.0"
style="-fx-border-color: #ffd308; -fx-border-radius: 30;" text="Hinweis"
textFill="WHITE">
<font>
<Font name="Franklin Gothic Medium Cond" size="26.0" />
</font>
</Button>
</children>
</Pane>
<CheckBox id="checkboxSoundeffect" fx:id="checkboxSoundeffect"
layoutX="1032.0" layoutY="23.0" mnemonicParsing="false"
onAction="#handleCheckboxSoundEffect" text="Soundeffekte" textFill="WHITE" />
<CheckBox id="checkboxMusic" fx:id="checkboxMusic" layoutX="1185.0"
layoutY="23.0" mnemonicParsing="false" onAction="#handleCheckboxMusic"
text="Musik" textFill="WHITE" />
<Label fx:id="labelLevel" layoutX="33.0" layoutY="14.0"
prefHeight="49.0" prefWidth="136.0" text="Level 1" textAlignment="CENTER"
textFill="WHITE">
<font>
<Font name="Franklin Gothic Medium Cond" size="40.0" />
</font>
</Label>
</children>
</Pane>
拜托,有人知道如何解决这个问题吗?我整天都在寻找解决方案,慢慢变得疯狂 - .-
编辑:当在Eclipse中触发错误运行时,也会发生此错误:
javafx.fxml.LoadException:
/C:/Users/bertr/eclipse-workspace/Hashiwokakero2/bin/application/resources/Layout.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2571)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at application.Main.start(Main.java:24)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2566)
... 12 more
Caused by: java.lang.Error: Unresolved compilation problem:
Invalid argument to operation ++/--
at application.view.Controller.initialize(Controller.java:70)
... 22 more