Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NullPointerException in a problematic point of code  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In one of my NetBeans 6.5.1 projects
there is an ordinary MIDlet
which should be able to change the Canvas used by the MIDlet
in method startApp.
The MIDlet class is as follows:

public class OSMIDlet extends MIDlet implements CommandListener

* Called when MIDlet is started.
* Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
public void startApp() {
if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();

WelcomeJK pictureSequence = new WelcomeJK (this);

Display.getDisplay (this).setCurrent (pictureSequence);

midletPaused = false;


} /* end class 'OSMIDlet' */

Now when using the debugger of NetBeans 6.5.1 IDE
it turns out that the line

Display.getDisplay (this).setCurrent (pictureSequence);

causes a NullPointerException to be thrown.
It seems that trying to catch that exception does not help
in finding out where the problem is since
it really seems that the Display object
given by Display.getDisplay (this) is null
while there should be existing a reference to a valid object.
Method Display.setCurrent (Displayable?) should not
throw a NullPointerException if variable pictureSequence is null.

Could you please help me to resolve this problem? Thank you.

Kind regards,

Lauri J. Martikainen
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!