即使FXML文件中的路径正确并且没有不匹配的fx:id,控制器也会引发javafx.fxml.LoadException

时间:2019-05-18 13:09:31

标签: javafx fxml

一旦在FXML文件中设置了Controller,FXMLLoader似乎就无法工作。如果我未在SceneBuilder中设置控制器,则会显示FXML文件中的所有元素。在控制器就位的情况下,代码在FXMLLoader处停止,并且不再执行。

我尝试将控制器直接写入fxml文件,以防问题来自SceneBuilder,但无济于事。我也从以前的场景中使用的简单的Pane切换到AnchorPane,同样没有结果。   当程序抛出LoadException时,我试图查看我是否有一些fx:id在Controller中没有正确的corespondent,但是即使我在SceneBuilder和Controll中都删除了它们之后,该程序仍然无法正常工作。   控制器和FXML文件都在同一文件夹中,因此例外不是来自路径。

管制员学生注意:

public class StudentNote implements Initializable {


public StudentNote(AnchorPane pane){
    try{
    showUI(pane);}
    catch (Exception e){
        e.printStackTrace();
    }
}

private void showUI(AnchorPane pane) throws Exception{
    pane.getChildren().clear();
    Parent root= FXMLLoader.load(getClass().getResource("studentNote.fxml"));
    pane.getChildren().add(root);
    //tabelaNote.setItems(getNote());
}


public ObservableList<Nota> getNote(){
    ObservableList<Nota> note= FXCollections.observableArrayList();
    Nota nota=new Nota(9,"15-05-2019","Andrei","Nu");
    note.add(nota);
    return note;
}


@Override
public void initialize(URL location, ResourceBundle resources) { 
    //coloanaNota.setCellValueFactory(new PropertyValueFactory<>("nota"));
    //coloanaData.setCellValueFactory(new PropertyValueFactory<>("data"));
    //coloanaProfesor.setCellValueFactory(new PropertyValueFactory<>("profesor"));
    //coloanaTeza.setCellValueFactory(new PropertyValueFactory<>("isTeza"));
    //tabelaNote.setItems(getNote());


 }
}

FXML:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>


<AnchorPane prefHeight="741.0" prefWidth="1320.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="StudentNote">

StackTrace:

    javafx.fxml.LoadException: 
    /E:/GitHub/E-Catalog/Client/out/production/Client/studentNote.fxml:19

  at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
  at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:103)
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:932)
  at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
  at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
  at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
  at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
  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 StudentNote.showUI(StudentNote.java:29)
  at StudentNote.<init>(StudentNote.java:21)
  at Student.lambda$initialize$0(Student.java:82)
  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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
  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.control.MenuItem.fire(MenuItem.java:462)
  at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1405)
  at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$343(ContextMenuContent.java:1358)
  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.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:3757)
  at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
  at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
  at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$358(GlassViewEventHandler.java:432)
  at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
  at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
  at com.sun.glass.ui.View.notifyMouse(View.java:937)
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
  at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.InstantiationException: StudentNote
  at java.lang.Class.newInstance(Class.java:427)
  at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
  ... 57 more
Caused by: java.lang.NoSuchMethodException: StudentNote.<init>()
  at java.lang.Class.getConstructor0(Class.java:3082)
  at java.lang.Class.newInstance(Class.java:412)
  ... 59 more

0 个答案:

没有答案