Javafx Scene Builder Project is not 运行(提示运行时错误)
Javafx Scene Builder Project is not running (Prompt runtime error)
我的 javafx 文件有问题 运行,我是 javafx 的新手。所以我想知道为什么以及如何解决这个错误。 fxml 文件只是我对过去几年的作业所做的一个小实验。所以我希望有人能帮我弄清楚为什么我的程序不是 运行。
我的观点class
包视图;
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{
private Stage stage;
public static void main(String args []) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
stage.setTitle("Main Menu");
stage.setScene(scene);
stage.show();
}
}
我的fxml生成代码
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.ColorInput?>
<?import javafx.scene.effect.Glow?>
<?import javafx.scene.effect.Light.Distant?>
<?import javafx.scene.effect.Lighting?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx/9.0.1"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<AnchorPane prefHeight="562.0" prefWidth="592.0">
<children>
<Button layoutX="32.0" layoutY="73.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Session Maintenance">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="314.0" layoutY="167.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Apply Membership">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="314.0" layoutY="73.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Seating Maintenance">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="32.0" layoutY="167.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Ticketing Maintenance">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="174.0" layoutY="262.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Exit">
<font>
<Font size="18.0" />
</font>
</Button>
<ImageView fitHeight="212.0" fitWidth="245.0" layoutX="14.0" layoutY="336.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@JS.png" />
</image>
</ImageView>
<TextField alignment="CENTER" layoutX="251.0" layoutY="492.0" prefHeight="56.0" prefWidth="327.0" text="Customer Hotline - 0199660803 / 0172599389">
<effect>
<Lighting diffuseConstant="1.37" specularConstant="0.37" specularExponent="40.0" surfaceScale="0.8">
<bumpInput>
<ColorInput />
</bumpInput>
<light>
<Light.Distant color="#33dbf2" />
</light>
</Lighting>
</effect>
</TextField>
</children>
<effect>
<Glow level="0.0" />
</effect>
</AnchorPane>
<TextField alignment="CENTER" prefHeight="0.0" prefWidth="592.0" text="Welcome to JS Rocket Systems">
<font>
<Font size="26.0" />
</font>
</TextField>
</children>
</AnchorPane>
提示的错误
Exception in Application start method
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 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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication4(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at view.Main.start(Main.java:21)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication11(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait4(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null2(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater3(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$null7(WinApplication.java:177)
... 1 more
Exception running application view.Main
谁能告诉我如何解决这个问题以及如何获得它 运行?谢谢!
验证您的 fxml 文件的名称和 URL 是否正确
Parent root = FXMLLoader.load(getClass().getResource("/view/Main.fxml"));
从 fxml 文件中删除时出现错误
<light>
<Light.Distant color="#33dbf2" />
</light>
从 XML 文件中删除该行后。
我的 javafx 文件有问题 运行,我是 javafx 的新手。所以我想知道为什么以及如何解决这个错误。 fxml 文件只是我对过去几年的作业所做的一个小实验。所以我希望有人能帮我弄清楚为什么我的程序不是 运行。
我的观点class 包视图;
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{
private Stage stage;
public static void main(String args []) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
stage.setTitle("Main Menu");
stage.setScene(scene);
stage.show();
}
}
我的fxml生成代码
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.ColorInput?>
<?import javafx.scene.effect.Glow?>
<?import javafx.scene.effect.Light.Distant?>
<?import javafx.scene.effect.Lighting?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx/9.0.1"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<AnchorPane prefHeight="562.0" prefWidth="592.0">
<children>
<Button layoutX="32.0" layoutY="73.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Session Maintenance">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="314.0" layoutY="167.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Apply Membership">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="314.0" layoutY="73.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Seating Maintenance">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="32.0" layoutY="167.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Ticketing Maintenance">
<font>
<Font size="18.0" />
</font>
</Button>
<Button layoutX="174.0" layoutY="262.0" mnemonicParsing="false" prefHeight="61.0" prefWidth="245.0" text="Exit">
<font>
<Font size="18.0" />
</font>
</Button>
<ImageView fitHeight="212.0" fitWidth="245.0" layoutX="14.0" layoutY="336.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@JS.png" />
</image>
</ImageView>
<TextField alignment="CENTER" layoutX="251.0" layoutY="492.0" prefHeight="56.0" prefWidth="327.0" text="Customer Hotline - 0199660803 / 0172599389">
<effect>
<Lighting diffuseConstant="1.37" specularConstant="0.37" specularExponent="40.0" surfaceScale="0.8">
<bumpInput>
<ColorInput />
</bumpInput>
<light>
<Light.Distant color="#33dbf2" />
</light>
</Lighting>
</effect>
</TextField>
</children>
<effect>
<Glow level="0.0" />
</effect>
</AnchorPane>
<TextField alignment="CENTER" prefHeight="0.0" prefWidth="592.0" text="Welcome to JS Rocket Systems">
<font>
<Font size="26.0" />
</font>
</TextField>
</children>
</AnchorPane>
提示的错误
Exception in Application start method
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 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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication4(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at view.Main.start(Main.java:21)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication11(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait4(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null2(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater3(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$null7(WinApplication.java:177)
... 1 more
Exception running application view.Main
谁能告诉我如何解决这个问题以及如何获得它 运行?谢谢!
验证您的 fxml 文件的名称和 URL 是否正确
Parent root = FXMLLoader.load(getClass().getResource("/view/Main.fxml"));
从 fxml 文件中删除时出现错误
<light>
<Light.Distant color="#33dbf2" />
</light>
从 XML 文件中删除该行后。