I am having a runtime error that states Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Status.copyState(Status.java:29) This is a class that is call the an instance of the Status calls (st): Main class is:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/**
*
*
* @author (Jason Sizemore)
* @version (11-20-09 HW09)
*/
public class BetterCalculator extends Calculator
{
//attributes
private JButton undo;
private String undoText;
private Status st;
public BetterCalculator()
{
super();
st = new Status();
}
public void createUserInterface3()
{
createUserInterface2();
undo = new JButton("undo");
jPanel.add(undo);
undo.setBackground(Color.red);
undo.setToolTipText("This is the undo feature");
undo.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
super.actionPerformed(e);
while(displayBox.getText() != null)
{
st.copyState();
}
if(e.getSource() == undo)
{
Status st;
st = new Status();
undoText = st.returnState();
displayBox.setText(undoText);
}
}
public static void main(String[] args)
{
BetterCalculator myCalc;
myCalc = new BetterCalculator();
myCalc.createUserInterface3();
}
}
It is call the an instance of Status (st) Here is the Status class
import java.util.*;
import java.awt.event.*;
import java.awt.*;
/**
* Write a description of class Status here.
*
* @author (Jason Sizemore )
* @version (HW09 11-21-09)
* This is a class to get the status for the undo feature
*/
public class Status extends BasicCalculator
{
//attributes
private ArrayList<String> lastState;
public String ls;
public String rls;
//constructors
public Status()
{
lastState = new ArrayList<String>(10);
}
//Methods
public void copyState()
{
//operand1 = Double.parseDouble(displayBox.getText());
ls = displayBox.getText();
lastState.add(ls);
}
public String returnState()
{
int sizeOfArrayList;
sizeOfArrayList = lastState.size();
rls = lastState.get(sizeOfArrayList);
return rls;
}
}
I know the issue is with the line ls = displayBox.getText(); I have a object take the return of a method on a object. what am I missing here.
Thanks for any help.