从场景重新加载主舞台上的网格窗格

时间:2017-07-23 03:54:07

标签: javafx controller

晚上好,

我试过寻找这个解决方案,但我似乎找不到一个。我在日历上有一个创建约会的场景。我希望在创建约会后使用给定方法更新主阶段。我尝试的一切都给了我一个nullpointer,因为控制器没有正确启动。下面的代码在我的CalendarController中:

  public  void loadMonth(LocalDateTime ldt)
{

    if(gpMain.getChildren().size() > 0)
    {
        gpMain.getChildren().clear();
    }

    loadGridPaneFirstRow();
    //More code

这是我的预约控制器

     private void addAppt() throws SQLException {
       if(checkfileds()){
          String customer = (String)customerselector.getValue();
          String apttype = (String)appttype.getValue();
          String aptdesc = apptdetail.getText();

          String combinedstart = calDate.toLocalDate().toString() + " " + starttime.getValue().toString();
          String combinedend = calDate.toLocalDate().toString() + " " + stoptime.getValue().toString();


    try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO appointment (title, description, url, start, end, createdDate, createdBy, lastUpdateBy, customerID, location, contact) SELECT ?,?,?,?,?,?,?,?, a.customerID, b.city, c.phone FROM customer a INNER JOIN address c ON a.addressID = c.addressID INNER JOIN city b ON b.cityID = c.cityID WHERE a.customername='" + customer + "' "))
    {
    stmt.setString(1, apttype);
    stmt.setString(2, aptdesc);
    stmt.setString(3, "https://www.softwareinccorp.com");
   if(isOverlapping(java.sql.Timestamp.valueOf(combinedstart),java.sql.Timestamp.valueOf(combinedend) )){
        Alert alert = Bundles.alertforWarning("overlap", "error","error");
        alert.showAndWait();
        return;
   }
    stmt.setTimestamp(4, java.sql.Timestamp.valueOf(combinedstart));
    stmt.setTimestamp(5, java.sql.Timestamp.valueOf(combinedend));
    stmt.setString(6, dateFormat.format(date));
    stmt.setString(7, username);
    stmt.setString(8, dateFormat.format(date));

    stmt.executeUpdate();
    }

    try (PreparedStatement stmt2 = conn.prepareStatement("INSERT INTO reminder (reminderID, reminderDate, snoozeIncrement, snoozeIncrementTypeId, createdBy, createdDate, remindercol, appointmentID ) SELECT ?,?,?,?,?,?,?, a.appointmentID FROM appointment a INNER JOIN customer c ON a.customerid = c.customerid WHERE c.customername='" + customer + "' "))
    {
    Timestamp ts = new Timestamp(java.sql.Timestamp.valueOf(combinedstart).getTime());
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(ts.getTime());
    cal.add(Calendar.MINUTE, -15);
    ts = new Timestamp(cal.getTime().getTime());
    stmt2.setInt(1, count);
    stmt2.setTimestamp(2, ts);
    stmt2.setInt(3, 5);
    stmt2.setInt(4, count++);
    stmt2.setString(5, username);
    stmt2.setString(6, dateFormat.format(date));
    stmt2.setString(7, "reminder"); 
    stmt2.executeUpdate();


    }  
        controller.loadMonth(calDate); //causing issues
        Stage stage;
                         stage = (Stage)addappt.getScene().getWindow();
                         stage.close();

}


}  

每当我尝试从约会控制器重新加载网格面板时,我都会得到一个nullpointerexception。请指教。

编辑:这是请求的例外日志

     Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
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:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
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: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:381)
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$354(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
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:748)
        Caused by: java.lang.reflect.InvocationTargetException
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:1769)
... 48 more
        Caused by: java.lang.NullPointerException
at software2.AppointmentController.addAppt(AppointmentController.java:322)
at software2.AppointmentController.lambda$addbuttonfired$1(AppointmentController.java:135)
at java.util.Optional.ifPresent(Optional.java:159)
at software2.AppointmentController.addbuttonfired(AppointmentController.java:133)
... 58 more

0 个答案:

没有答案