Hi all,
I'm trying to make the venerable splash screen code from Sun's Tech Tip Archive work.
For emulators (in Sun Studio Mobility 6) that are WTK 1.04, it works fine. However, for emulators that are WTK 2.1 or any emulator so far from Nokia's Developer Suite, it throws a NullPointerException that seems to be related to the g.drawImage (...) call.
Anyone see this before? I'll append the code and then the exception trace.
=======
class SplashScreen extends Canvas {
private Display display;
private Displayable next;
private Timer timer = new Timer();
private Image img;
SplashScreen(Display display, Displayable next) {
this.display = display;
this.next = next;
display.setCurrent(this);
try {
img = Image.createImage("/DivvyUp.png");
}
catch (IOException e) {
throw new RuntimeException("Can't load image. " + e);
}
}
protected void keyPressed( int keyCode ) {
dismiss();
}
protected void paint(Graphics g) {
g.setGrayScale(255);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(img, getWidth() / 2, getHeight() / 2, Graphics.HCENTER | Graphics.VCENTER);
}
protected void pointerPressed( int x, int y ) {
dismiss();
}
protected void showNotify() {
timer.schedule(new CountDown(), 5000);
}
private void dismiss() {
timer.cancel();
display.setCurrent( next );
}
private class CountDown extends TimerTask {
public void run() {
dismiss();
}
}
}
=======
Running with storage root DefaultColorPhone
java.lang.NullPointerException:
at SplashScreen.paint(+42)
at javax.microedition.lcdui.Canvas.callPaint(+80)
at javax.microedition.lcdui.Display.repaint(+78)
at javax.microedition.lcdui.Display.registerNewCurrent(+238)
at javax.microedition.lcdui.Display.access$400(+6)
at javax.microedition.lcdui.Display$DisplayAccessor.foregroundNotify(+46)
at javax.microedition.lcdui.Display$DisplayManagerImpl.notifyWantsForeground(+153)
at javax.microedition.lcdui.Display$DisplayManagerImpl.access$100(+6)
at javax.microedition.lcdui.Display.setCurrentImpl(+98)
at javax.microedition.lcdui.Display.setCurrent(+29)
at SplashScreen.<init>(+30)
at DivvyUpMIDlet.initMIDlet(+23)
at DivvyUpMIDlet.startApp(+11)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+266)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+116)
Execution completed.
382915 bytecodes executed
14 thread switches
494 classes in the system (including system classes)
2639 dynamic objects allocated (96700 bytes)
6 garbage collections (61624 bytes collected)

Reply With Quote


