google.ps,IllegalArgumentException

时间:2014-08-06 04:35:04

标签: java eclipse

你好我写这段代码,当我执行它时,给我以下例外,请帮助克服它::

try{
   model.insertRow(model.getRowCount(), new Object[]jTextField1.getText(),jTextField2.getText(),jTextField3.getText(),String.valueOf(jComboBox1.getSelectedItem())+"/"+String.valueOf(jComboBox2.getSelectedItem())+"/"+String.valueOf(jComboBox3.getSelectedItem()),jTextField4.getText(),jTextField5.getText()});
   ps=con.prepareStatement("insert into Outcome(OutID,Description,MoneyAmount,ODate,Notes)values(?,?,?,?,?)");
   ps.setString(1,jTextField1.getText());
   ps.setString(2,jTextField2.getText());
   ps.setString(3, jTextField3.getText());
   ps.setString(4,String.valueOf(jComboBox1.getSelectedItem())+"/"+String.valueOf(jComboBox2.getSelectedItem())+"/"+String.valueOf(jComboBox3.getSelectedItem()));
   ps.setString(5,jTextField4.getText());

   ps.executeQuery();

   ps.close();
   con.close();}

 catch(Exception ex){

          }             
    }

这给我以下例外:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Cannot format given Object as a Number
    at java.text.DecimalFormat.format(Unknown Source)
    at java.text.Format.format(Unknown Source)
    at javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer.configureValue(Unknown Source)
    at javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer.getTableCellRendererComponent(Unknown Source)
    at javax.swing.JTable.prepareRenderer(Unknown Source)
    at javax.swing.plaf.synth.SynthTableUI.paintCell(Unknown Source)
    at javax.swing.plaf.synth.SynthTableUI.paintCells(Unknown Source)
    at javax.swing.plaf.synth.SynthTableUI.paint(Unknown Source)
    at javax.swing.plaf.synth.SynthTableUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager$3.run(Unknown Source)
    at javax.swing.RepaintManager$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.access$1100(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

1 个答案:

答案 0 :(得分:0)

我认为初始化对象时代码中存在错误:

new Object[]jTextField1.getText(),jTextField2.getText(),jTextField3.getText(),String.valueOf(jComboBox1.getSelectedItem())+"/"+String.valueOf(jComboBox2.getSelectedItem())+"/"+String.valueOf(jComboBox3.getSelectedItem()),jTextField4.getText(),jTextField5.getText()}

{之后,你错过了一个开放的new Object。它应该是这样的:

new Object[]{jTextField1.getText(),jTextField2.getText(),jTextField3.getText(),String.valueOf(jComboBox1.getSelectedItem())+"/"+String.valueOf(jComboBox2.getSelectedItem())+"/"+String.valueOf(jComboBox3.getSelectedItem()),jTextField4.getText(),jTextField5.getText()}