Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems calling a method from another Java class
    text
    copied!<p>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:</p> <pre><code>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(); } } </code></pre> <p>It is call the an instance of Status (st) Here is the Status class</p> <pre><code>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&lt;String&gt; lastState; public String ls; public String rls; //constructors public Status() { lastState = new ArrayList&lt;String&gt;(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; } } </code></pre> <p>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.</p> <p>Thanks for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload