-2

getting NullPointerException on this part of code,

public RunningManCanvas(RunningMan midlet) throws Exception {
    super(true);
    System.out.println("ERROR");

    theDisplay = Display.getDisplay(midlet);
    theRunningMan = midlet;
    // Calculate the screen dimensions.
    DISP_WIDTH = getWidth();
    DISP_HEIGHT = getHeight();
}

What could be the reason?

gnat
  • 6,213
  • 108
  • 53
  • 73
mussi89
  • 99
  • 1
  • 3
  • 10

2 Answers2

1

The possible source of NPE in the code you posted is the statement Display.getDisplay(midlet).

API docs for this method explicitly state:

Throws:
     NullPointerException - if m is null

above, m refers to method parameter.

You can test if this is the case by extending the logging from

    System.out.println("ERROR");

to something like

    System.out.println("midlet is null: " + (midlet == null);
gnat
  • 6,213
  • 108
  • 53
  • 73
0

You need to provide some more information. It may be coming from your super constructor, midlet may may be null (I'd check this first), there could be something weird happening in Display.getDisplay(), or in either of the getWidth() or getHeight().

Kim Burgess
  • 467
  • 3
  • 15