Yahoo Answers is shutting down on 4 May 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 5

Why this Java command doesn't work?

I put this command in constructor and actionPerformed() method :

lblStatus.setText("Score : X = " + scorX + " , O = " + scorO + " , Turn = " + turn);

in constructor the command run well, but in actionPerformed(), the command always raise NullPointerException. But the whole program not stopped and still running. do you know why? and what's the solution? TIA

2 Answers

Relevance
  • 10 years ago
    Favourite answer

    A NullPointerException means that something either has not been defined or has not been given an initial value.

    Given that an actionPerformed() can be triggered at the start of a program Perhaps your lblStatus does not exist or has not been correctly defined at the point in time that the Exception occurs.

    Perhaps you need a condition statement to only set the status after an event. That event could just be the completion of the screen.

    Have fun.

  • 10 years ago

    Just taking a wild guess here, but maybe you have to pass the variables to the function?

    For example, actionPerformed()

    should be

    actionPerformed(scorX, ScorO, turn)

Still have questions? Get answers by asking now.