我似乎没有找到适合我的问题的解决方案。在加载 EntryView.fxml 文件时,我总是得到一个 NPE。我已经尝试了几种路径格式(例如相对、绝对)。我对它的工作原理有误解还是一个简单的错误?所有这些文件都在一个包中。
这是错误日志的顶部:
Mär 13, 2015 1:09:26 PM de.quest2go.authortool.entry.EntryController$1 handle
SCHWERWIEGEND: null
javafx.fxml.LoadException:
/Users/timzeidler/Uni/MCS/AuthortoolI/bin/de/quest2go/authortool/entry/EventEditView.fxml:9
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:918)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3208)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
at de.quest2go.authortool.entry.EntryController$1.handle(EntryController.java:64)
at de.quest2go.authortool.entry.EntryController$1.handle(EntryController.java:1)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
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:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8216)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
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$MouseHandler.process(Scene.java:3724)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3452)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1728)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2461)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:348)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:273)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:382)
at com.sun.glass.ui.View.handleMouseEvent(View.java:553)
at com.sun.glass.ui.View.notifyMouse(View.java:925)
Caused by: java.lang.ClassNotFoundException: /EventEditController.java
简短的 FXML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="EntryContoller.java">
<children>
<Button fx:id="eventBtn" layoutX="91.0" layoutY="319.0" mnemonicParsing="false" text="EventScene" />
<Button layoutX="270.0" layoutY="319.0" mnemonicParsing="false" text="ItemScene" />
<Button layoutX="457.0" layoutY="319.0" mnemonicParsing="false" text="EpisodeScene" />
</children>
</Pane>
主要:
public class EntryMain extends Application {
private Stage stage;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(EntryMain.class, (java.lang.String[])null);
}
@Override
public void start(Stage primaryStage) {
try {
stage = primaryStage;
Parent root = FXMLLoader.load(getClass().getResource("EntryView.fxml"));
//VBox page = (VBox) FXMLLoader.load(EntryMain.class.getResource("EntryView.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Autorentool");
primaryStage.show();
} catch (Exception ex) {
Logger.getLogger(EntryMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
并且带有 FXMlLoader 的控制器有问题。
public class EntryController {
private Node node;
private Stage stage;
private Scene scene;
private FXMLLoader fxmlLoader;
private Parent root;
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="episodenEditorBtn"
private Button episodenEditorBtn; // Value injected by FXMLLoader
@FXML // fx:id="eventEditorBtn"
private Button eventEditorBtn; // Value injected by FXMLLoader
@FXML // fx:id="itemEditorBtn"
private Button itemEditorBtn; // Value injected by FXMLLoader
@FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert episodenEditorBtn != null : "fx:id=\"episodenEditorBtn\" was not injected: check your FXML file 'EntryView.fxml'.";
assert eventEditorBtn != null : "fx:id=\"eventEditorBtn\" was not injected: check your FXML file 'EntryView.fxml'.";
assert itemEditorBtn != null : "fx:id=\"itemEditorBtn\" was not injected: check your FXML file 'EntryView.fxml'.";
eventEditorBtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("EventEditView.fxml"));
//VBox page = (VBox) FXMLLoader.load(EntryMain.class.getResource("EntryView.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Autorentool");
stage.show();
} catch (Exception ex) {
Logger.getLogger(EntryMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
提前感谢您帮助我。