3

I have an input panel and want to call a method in another class when the button is pressed but am getting a null pointer exception. Was hoping someone might be able to tell me what I'm doing wrong?

Here is the code causing it:

public void actionPerformed(ActionEvent ae)
    {
        if (ae.getSource() == resultsButton)
        {
            jbTour.processAdditionalResult();
        }

    }


public void processAdditionalResult()
    {
        System.out.println("button pressed");
    }
2
  • Add the exception stack traces, then we can find the error easily.. Commented Jan 7, 2012 at 18:50
  • Which line is causing the exception? Commented Jan 7, 2012 at 18:51

3 Answers 3

3

You need to initialize jbTour: jbTour = new JBTourObject() (or whatever) so that it is not null before the actionPerformed method gets invoked.

Sign up to request clarification or add additional context in comments.

Comments

1

I think I can tell even without the stack trace: jbTour is null. You've declared a name of that reference type in the class that implements the ActionListener interface, but you never initialized it to point a new reference.

Comments

1

If this throws a NullPointerException

jbTour.processAdditionalResult();

that means jbTour has not been set or is null.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.