我正在尝试使用javafx构建一个基本UI,我之前已经完成了几次。出于某种原因,我遇到了这个:
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$launchApplication$155(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 Main.Main.start(Main.java:18)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
... 1 more
运行应用程序Main.Main
的异常我不明白我做错了什么,因为这从未发生在我身上,我以与之前相同的方式重复了这个过程。 日食布局照片: https://gyazo.com/b77d2ceace61eef8ed2526686f6763f0?token=d3f747ca001b7e411d721c12cd54b46a 码: Main.java:
package Main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Pane mainPane = (Pane) FXMLLoader.load(Main.class.getResource("Main.fxml"));
primaryStage.setScene(new Scene(mainPane));
primaryStage.show();
}
}
myController.java:
package Main;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.TextField;
public class myController {
@FXML
private TextField quantity;
@FXML
private Button adding;
@FXML
private ScrollBar currentP;
@FXML
private Label message;
@FXML
private ComboBox<?> stocks;
@FXML
private Button remove;
@FXML
void itemPicked(ActionEvent event) {
}
@FXML
void getIndexC(ActionEvent event) {
}
@FXML
void deleteItem(ActionEvent event) {
}
@FXML
void addItem(ActionEvent event) {
}
@FXML
void getQuantity(ActionEvent event) {
}
}
Main.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.layout.AnchorPane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="1280.0" stylesheets="@myStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="myController">
<children>
<ImageView fitHeight="568.0" fitWidth="684.0" layoutX="356.0" layoutY="167.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../Pictures/builder.jpg" />
</image>
</ImageView>
<ImageView fitHeight="885.0" fitWidth="857.0" layoutX="629.0" layoutY="187.0" pickOnBounds="true" preserveRatio="true" rotate="90.0">
<image>
<Image url="@../../../Pictures/Uroburos-rootkit-Espionage-Russia.jpg" />
</image>
</ImageView>
<ImageView fitHeight="885.0" fitWidth="857.0" layoutX="-187.0" layoutY="187.0" pickOnBounds="true" preserveRatio="true" rotate="90.0">
<image>
<Image url="@../../../Pictures/Uroburos-rootkit-Espionage-Russia.jpg" />
</image>
</ImageView>
<Line endX="100.0" endY="400.0" layoutX="381.0" layoutY="324.0" startX="100.0" startY="-325.0" />
<Line endX="425.0" endY="390.0" layoutX="391.0" layoutY="334.0" startX="425.0" startY="-335.0" />
<ComboBox fx:id="stocks" layoutX="38.0" layoutY="135.0" onAction="#itemPicked" prefHeight="46.0" prefWidth="421.0" promptText="Please Select and Item" />
<ScrollBar fx:id="currentP" layoutX="857.0" layoutY="108.0" onDragDetected="#getIndexC" orientation="VERTICAL" prefHeight="100.0" prefWidth="400.0" />
<Button fx:id="remove" layoutX="1007.0" layoutY="53.0" mnemonicParsing="false" onAction="#deleteItem" prefHeight="43.0" prefWidth="250.0" text="Remove From Order">
<font>
<Font name="Arial Black" size="20.0" />
</font>
</Button>
<ImageView fitHeight="72.0" fitWidth="79.0" layoutX="491.0" layoutY="74.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../Pictures/Uroburos-rootkit-Espionage-Russia.jpg" />
</image>
</ImageView>
<Label layoutX="491.0" layoutY="14.0" prefHeight="60.0" prefWidth="311.0" text="RootKit At your Service" textAlignment="JUSTIFY">
<font>
<Font name="Courier New Bold Italic" size="22.0" />
</font>
</Label>
<Label fx:id="message" layoutX="587.0" layoutY="87.0" text=""Protecting" your trade">
<font>
<Font name="Courier New Italic" size="15.0" />
</font>
</Label>
<Button fx:id="adding" layoutX="38.0" layoutY="81.0" mnemonicParsing="false" onAction="#addItem" text="Add Item To Order">
<font>
<Font name="Arial Black" size="20.0" />
</font>
</Button>
<TextField fx:id="quantity" layoutX="38.0" layoutY="194.0" onAction="#getQuantity" prefHeight="54.0" prefWidth="62.0" promptText=""1"">
<font>
<Font size="20.0" />
</font></TextField>
<Label layoutX="108.0" layoutY="196.0" text="Quantity" textFill="WHITE">
<font>
<Font name="Arial Black" size="34.0" />
</font>
</Label>
</children>
</Pane>
CSS文件目前为空。 我想整体获得GUI显示,但由于某种原因找不到位置,由于某种原因,我有另一个错误,我甚至无法识别。 感谢提前帮助&lt; 3
答案 0 :(得分:0)
在FXML文件中,您的控制器需要为Main.myController
。控制器规范需要完全合格。