JavaFX程序出错

时间:2013-06-15 23:58:57

标签: java hibernate javafx

我在JavaFX中创建了一个程序,并且该寄存器具有两个日期和时间字段,这些字段在注册时填充。使用带有注释的hibernate来进行映射,当我提交日期和时间时它会生成此错误并将保存:

java.lang.RuntimeException: java.lang.IllegalArgumentException

at br.upf.ads.daoo.global.action.AbstractAction.actionPerformed(AbstractAction.java:63)

at br.upf.ads.daoo.global.controller.AbstractController.handle(AbstractController.java:156)

at br.upf.ads.daoo.global.controller.AbstractController.handle(AbstractController.java:31)

at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)

at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)

at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)

at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)

at javafx.event.Event.fireEvent(Event.java:171)

at javafx.scene.Node.fireEvent(Node.java:6863)

at javafx.scene.control.Button.fire(Button.java:179)

at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)

at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)

at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)

at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)

at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)

at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)

at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)

at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)

at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)

at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)

at javafx.event.Event.fireEvent(Event.java:171)

at javafx.scene.Scene$MouseHandler.process(Scene.java:3328)

at javafx.scene.Scene$MouseHandler.process(Scene.java:3168)

at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3123)

at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563)

at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2265)

at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)

at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)

at com.sun.glass.ui.View.handleMouseEvent(View.java:528)

at com.sun.glass.ui.View.notifyMouse(View.java:922)

at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)

at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)

at java.lang.Thread.run(Thread.java:722)

引起:java.lang.IllegalArgumentException

at java.util.Date.parse(Date.java:615)

at java.util.Date.<init>(Date.java:272)

at br.upf.ads.daoo.ui.CompraIncluirView.loadCompraFromPanel(CompraIncluirView.java:179)

at br.upf.ads.daoo.ui.CompraIncluirView.getCompra(CompraIncluirView.java:205)

at br.upf.ads.daoo.controller.CompraIncluirController$4.conditional(CompraIncluirController.java:58)

at br.upf.ads.daoo.global.action.ConditionalAction.action(ConditionalAction.java:51)

at br.upf.ads.daoo.global.action.AbstractAction.actionPerformed(AbstractAction.java:58)

... 50 more

可能是什么错误?下面是一些我认为是错误的代码:

private Compra loadCompraFromPanel() {
    Integer id = null;
    try {
        id = Integer.parseInt(tfId.getText());
    } catch (Exception nex) {
    }    
     Date data = null;
    if (!tfData.getText().trim().isEmpty()) {
       data= new Date(tfData.getText());        
    }

     Float valor = null;
    try {
        valor = Float.parseFloat(tfValor.getText());
    } catch (Exception nex) {
    }

     Date horario = null;
    if (!tfHorario.getText().trim().isEmpty()) {
        horario = new Date(tfHorario.getText());  
    }
    Passageiro passageiro = cbPassageiro.getValue();
    Capital capital = cbCapital.getValue();


    return new Compra(id, data, valor, horario, passageiro, capital);
}

2 个答案:

答案 0 :(得分:1)

您收到错误,因为无法解析传递给new Date(String s)的值(tfData.getText()tfHorario.getText())。但是,您应该使用DateFormat而不是已弃用的Date构造函数。例如:

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date horario = null;
try {
  horario = df.parse(tfHorario.getText());
} catch (ParseException e) {
  // The user didn't provide a string in the correct format, show an error or something
}

另请参阅:SimpleDateFormat

答案 1 :(得分:0)

您收到IllegalArgumentException,因为您传递tfData.getText()(字符串)作为data的构造函数(Date):

data= new Date(tfData.getText());

Date的构造函数是:

Date()
Date(int year, int month, int date) //Deprecated
Date(int year, int month, int date, int hrs, int min) //Deprecated
Date(int year, int month, int date, int hrs, int min, int sec) //Deprecated
Date(long date)
Date(String s) //Deprecated

String返回的tfData.getText()不是Date(String s) (已弃用)构造函数的有效格式。