I’m working with android & canvas, my code works flawlessly for other than when the display resolution changes (ie. rotating the device) the app forcecloses and log cat shows:
FATAL EXCEPTION: Thread-367
java.lang.NullPointerException
at …doDraw()
The line it links the error to contains:
canvas.drawARGB(255, 0, 0, 0);
But I believe it doesn’t matter as long as it’s trying to draw something and shows the first thing I’m trying to draw.
Here’s my run loop:
@Override
public void run() {
while (mPlaying) {
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
if (mPlaying == true) updatePosition();
doDraw(c);
}
} finally {
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
Which I took directly from the LunarLander example. Now the crash doesn’t happen every time I rotate, but about 75% of the time.
Any ideas? Thanks 🙂
this may help you