Hi guys. So I'm building this code in java using NetBeans and literally this code has been working fine the entire time. I haven't changed anything about it and now it's giving me an error and I can't find out what's wrong. Can you please take a look for me? Thanks. Here's my code:
int MM = this.jComboBoxMM.getSelectedIndex();
int DD = this.jComboBoxDD.getSelectedIndex();
int YYYY = this.jComboBoxYYYY.getSelectedIndex();
int HH = this.jComboBoxHH.getSelectedIndex();
int mm = this.jComboBoxmm.getSelectedIndex();
if(MM == 0 || DD == 0 || YYYY == 0 || HH == 0 || mm == 0) {
jLabelInvalidDateTime.setVisible(true);
try
{
Double.parseDouble(jTextFieldAmount.getText());
jLabelInvalidAmount.setVisible(false);
}
catch(NumberFormatException e)
{
//not a double
jLabelInvalidAmount.setVisible(true);
}
} else {
jLabelInvalidDateTime.setVisible(false);
try
{
Double.parseDouble(jTextFieldAmount.getText());
jLabelInvalidAmount.setVisible(false);
}
catch(NumberFormatException e)
{
//not a double
jLabelInvalidAmount.setVisible(true);
}
if(Double.parseDouble(jTextFieldAmount.getText()) < 0) {
jLabelInvalidAmount.setVisible(true);
} else {
String DateTime = jComboBoxMM.getSelectedItem().toString() + "/" + jComboBoxDD.getSelectedItem().toString() + "/" + jComboBoxYYYY.getSelectedItem().toString() + " " + jComboBoxHH.getSelectedItem().toString() + ":" + jComboBoxmm.getSelectedItem().toString() + " " + jComboBoxAMPM.getSelectedItem().toString();
DefaultTableModel model = (DefaultTableModel) jTableRunningTotal.getModel();
int rows = jTableRunningTotal.getRowCount();
model.setRowCount(rows - 3);
if(jRadioButtonWithdraw.isSelected()){
Double Amount = Double.parseDouble("-" + jTextFieldAmount.getText());
model.addRow(new Object[]{jTextFieldLocation.getText(), jTextFieldContainer.getText(), Amount, DateTime, jComboBoxNameofPerson.getSelectedItem().toString(), jTextFieldReason.getText()});
} else {
Double Amount = Double.parseDouble(jTextFieldAmount.getText());
model.addRow(new Object[]{jTextFieldLocation.getText(), jTextFieldContainer.getText(), Amount, DateTime, jComboBoxNameofPerson.getSelectedItem().toString(), jTextFieldReason.getText()});
}
jTableRunningTotal.selectAll();
double Total = 0.0;
int selectedRow[] = jTableRunningTotal.getSelectedRows();
for (int i : selectedRow) {
Total = Total + Double.parseDouble(jTableRunningTotal.getValueAt(i, 2).toString());
}
jTableRunningTotal.clearSelection();
model.addRow(new Object[]{"","","","","",""});
model.addRow(new Object[]{"","","","","",""});
model.addRow(new Object[]{"Total","",Total,"","",""});
//jMenuItemSave.setEnabled(true);
jRadioButtonWithdraw.setSelected(false);
jRadioButtonDeposit.setSelected(false);
jLabelDateTime.setEnabled(false);
jComboBoxMM.setEnabled(false);
jComboBoxMM.setSelectedIndex(0);
jComboBoxDD.setEnabled(false);
jComboBoxDD.setSelectedIndex(0);
jComboBoxYYYY.setEnabled(false);
jComboBoxYYYY.setSelectedIndex(0);
jComboBoxHH.setEnabled(false);
jComboBoxHH.setSelectedIndex(0);
jComboBoxmm.setEnabled(false);
jComboBoxmm.setSelectedIndex(0);
jComboBoxAMPM.setEnabled(false);
jComboBoxAMPM.setSelectedIndex(0);
jLabelInvalidDateTime.setVisible(false);
jLabelInvalidDateTime.setEnabled(false);
jLabelAmount.setEnabled(false);
jTextFieldAmount.setEnabled(false);
jTextFieldAmount.setText("0.00");
jLabelInvalidAmount.setVisible(false);
jLabelInvalidAmount.setEnabled(false);
jLabelLocation.setEnabled(false);
jTextFieldLocation.setEnabled(false);
jTextFieldLocation.setText("");
jLabelContainer.setEnabled(false);
jTextFieldContainer.setEnabled(false);
jTextFieldContainer.setText("");
jTextFieldReason.setEnabled(false);
jTextFieldReason.setText("");
jButtonOK.setEnabled(false);
jButtonCancel.setEnabled(false);
jButtonClear.setEnabled(false);
jLabelAddedBy.setEnabled(false);
jComboBoxNameofPerson.setEnabled(false);
jLabelReason.setEnabled(false);
jTextFieldReason.setEnabled(false);
jTextFieldReason.setText("");
}
}
Here's what I get from the Output Bar:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Cannot format given Object as a Number
at java.text.DecimalFormat.format(DecimalFormat.java:507)
at java.text.Format.format(Format.java:157)
at javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer.configureValue(SynthTableUI.java:802)
at javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer.getTableCellRendererComponent(SynthTableUI.java:789)
at javax.swing.JTable.prepareRenderer(JTable.java:5723)
at javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:683)
at javax.swing.plaf.synth.SynthTableUI.paintCells(SynthTableUI.java:580)
at javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:364)
at javax.swing.plaf.synth.SynthTableUI.update(SynthTableUI.java:275)
at javax.swing.JComponent.paintComponent(JComponent.java:780)
at javax.swing.JComponent.paint(JComponent.java:1056)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JViewport.paint(JViewport.java:728)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1579)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1502)
at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
And here's a screenshot of the form to help you better visualize it:
Tell me if you need anything else. I'm fairly new to Java. Any help would be appreciated. Thank you.