将数据从一种形式传输到另一种形式时出错

时间:2016-03-25 12:12:06

标签: javafx nullpointerexception javafx-8

我将数据从一种形式传输到另一种形式时遇到错误。过程就像,当我点击第一张表格上的编辑按钮时,第二张表格将打开,有可供选择的客户列表进行编辑选项。一旦我点击任何客户,第二个表格将关闭,该客户的数据将显示在第一个表格的textfield中进行编辑。问题是当我这样做时,我遇到了我无法理解的错误。

@FXML
javafx.scene.control.TextField companyName_Create_Client;

在第一个控制器上编辑Clicked事件:

@FXML
protected void edit_Create_ClientClicked() {
    try {
        edit_Create_Client.setDisable(true);
        editClient = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("editClient.fxml"));
        Scene scene = new Scene(root);
        editClient.setScene(scene);
        editClient.setTitle("Select Client");
        editClient.initModality(Modality.APPLICATION_MODAL);
        editClient.initStyle(StageStyle.UTILITY);
        editClient.show();

    } catch (Exception e) {
        System.out.println("Error :" + e.getMessage());
    }
}

在第二个控制器中选择客户时的事件:

@FXML
protected void find_table_editClientClicked(){
    Stage previousStage=(Stage) find_editClient.getScene().getWindow();
    client client=(client) find_table_editClient.getSelectionModel().selectedItemProperty().getValue();
    mainController.fillDataToEdit(client.getCompanyName());
    previousStage.close();
}

在第一个控制器上填充数据的功能:

public void fillDataToEdit(String selectedCompany) {
    try {        
        //System.out.println("company :" + selectedCompany);
        Session session = new Configuration().configure().buildSessionFactory().openSession();
        Transaction transaction = session.beginTransaction();
        Iterator s = session.createQuery("from client where companyName='" + selectedCompany + "'").iterate();
        client client = (client) s.next();
        System.out.println("company2 :" + client.getCompanyName());
        String com=client.getCompanyName();
        companyName_Create_Client.setText(com);

        transaction.commit();
        session.close();
    } catch (Exception e) {
        System.out.println("Error :" + e.getMessage());
        e.printStackTrace();
    }
}

错误来自companyName_Create_Client.setText(com);行。

错误:

company2 :Demo Company  // see, data from 2nd form is comming still error while assigning to textfield of 1st form
Error :null
java.lang.NullPointerException
at licensemonitoringsystem.mainController.fillDataToEdit(mainController.java:209)
at licensemonitoringsystem.EditClientController.find_table_editClientClicked(EditClientController.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
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:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
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:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
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$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案