Parent root = FXMLLoader.load(getClass().getResource("kibAr//kibArPerson.fxml"));
src包中的第12行kibAr包
C:\>java -jar person.jar
Exception in Application start method
Exception in thread "main" 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 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown So
urce)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(
Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$1/14832625.run(Unknow
n Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at kibAr.AnaEkran.start(AnaEkran.java:18)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153
(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/25863743.run(Unkno
wn Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown
Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/27949311.run(Unkno
wn Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Sourc
e)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/13569241.run(Unkno
wn Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown S
ource)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/31743054.run(Unkno
wn Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/7345883.run(Unknown So
urce)
... 1 more
在我运行jar文件没有显示窗口之后,我用Eclipse创建了jar文件(export> Runnable jar文件)..
从cmd运行jar文件后,我显示此错误。我怎么能解决这个问题?
答案 0 :(得分:1)
由于您没有展示可重复的示例,并且可能会出现一些问题,以下是一个可行的示例:
创建一个包应用程序并将此类放入其中:
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/application/Test.fxml"));
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
在包应用程序中创建“Test.fxml”。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<children>
<Pane layoutX="-125.0" layoutY="-143.0" prefHeight="200.0" prefWidth="200.0">
<children>
<Button layoutX="134.0" layoutY="161.0" mnemonicParsing="false" text="Button" />
</children>
</Pane>
</children>
</AnchorPane>
在Eclipse中选择
导出 - &gt; Runnable JAR文件 - &gt;将所需的库提取到生成的JAR
中(当然你需要指定正确的启动配置)
可以执行生成的JAR。
如果您还有其他内容,则必须在需要帮助时显示。