asiavoices
Programmer
Hello all,
I need help in figuring out an error during execution of my program.
How I got the error...
1. Using the GUI I created, I entered the info on the
form.
2. I clicked on an "ADD" button to add items to an Array.
3. That's when I got the error when I try to display the values.
Exception occurred during event dispatching:
java.lang.NullPointerException
at MyProg.actionPerformed(Assig10.java:374)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
......
Here is my code.........
/* ================================
* = Create the JTextFields =
* ================================ */
JTextField nameField = new JTextField(15);
JTextField moneyField = new JTextField(8);
JCheckBox isTaxField = new JCheckBox("Yes", true);
isTaxField.setMnemonic(KeyEvent.VK_Y);
isTaxField.setForeground(new Color(0,0,0));
isTaxField.setFont(new Font("Verdana", Font.BOLD, 11));
/* ========================================================
* = actionPerformed() method from =
* = ActionListener interface =
* ======================================================== */
public void actionPerformed(ActionEvent theButtonEvent)
{
if ( theButtonEvent.getActionCommand().equalsIgnoreCase("ADD")
{
recordCounter ++;
String theName = nameField.getText();
double thePrice = Double.parseDouble(moneyField.getText().trim());
boolean isTaxable = isTaxField.isSelected();
/* ---- Add the item method disabled for now ------*/
// addItem(theName, thePrice, isTaxable);
/*------------ for debugging... what are the values? ----------*/
System.out.println(theName + " " + thePrice + " " + isTaxable);
}
}
Desired action:
1. Print out the values of the 2 fields and checkbox.
2. If successful, they will be used as arguments to a method that will insert this new record in an ArrayList.
Thanks for your help,
Christopher
I need help in figuring out an error during execution of my program.
How I got the error...
1. Using the GUI I created, I entered the info on the
form.
2. I clicked on an "ADD" button to add items to an Array.
3. That's when I got the error when I try to display the values.
Exception occurred during event dispatching:
java.lang.NullPointerException
at MyProg.actionPerformed(Assig10.java:374)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
......
Here is my code.........
/* ================================
* = Create the JTextFields =
* ================================ */
JTextField nameField = new JTextField(15);
JTextField moneyField = new JTextField(8);
JCheckBox isTaxField = new JCheckBox("Yes", true);
isTaxField.setMnemonic(KeyEvent.VK_Y);
isTaxField.setForeground(new Color(0,0,0));
isTaxField.setFont(new Font("Verdana", Font.BOLD, 11));
/* ========================================================
* = actionPerformed() method from =
* = ActionListener interface =
* ======================================================== */
public void actionPerformed(ActionEvent theButtonEvent)
{
if ( theButtonEvent.getActionCommand().equalsIgnoreCase("ADD")
{
recordCounter ++;
String theName = nameField.getText();
double thePrice = Double.parseDouble(moneyField.getText().trim());
boolean isTaxable = isTaxField.isSelected();
/* ---- Add the item method disabled for now ------*/
// addItem(theName, thePrice, isTaxable);
/*------------ for debugging... what are the values? ----------*/
System.out.println(theName + " " + thePrice + " " + isTaxable);
}
}
Desired action:
1. Print out the values of the 2 fields and checkbox.
2. If successful, they will be used as arguments to a method that will insert this new record in an ArrayList.
Thanks for your help,
Christopher