I am making a simple 2d game for the Android platform that works fine with version 2.0 and higher, but when tested on device 1.6 it immediately crashes. When starting the debugger, it seems that I am getting a null pointer exception in the thread class. I'm just wondering if anyone has any ideas as to where the problem might be.
Here is the code for the stream class:
package com.marcusortiz.burnination;
import android.graphics.Canvas;
import android.view.SurfaceHolder;
public class GameThread extends Thread
{
private SurfaceHolder sHolder;
private MainView panel;
private boolean isRunning;
public GameThread(SurfaceHolder sHolder, MainView panel)
{
this.sHolder = sHolder;
this.panel = panel;
}
public void setRunning(boolean isRunning)
{
this.isRunning = isRunning;
}
public SurfaceHolder getSurfaceHolder()
{
return sHolder;
}
@Override
public void run()
{
Canvas canvas;
while(isRunning)
{
canvas = null;
try
{
canvas = sHolder.lockCanvas(null);
synchronized(sHolder)
{
for(Sprite s : panel.getSprites())
{
s.update();
}
panel.onDraw(canvas);
}
}
finally
{
if(canvas != null)
{
sHolder.unlockCanvasAndPost(canvas);
}
}
}
}
}
Perhaps there are some compatibility issues with this code that I don’t know about - I really get started when it comes to using threads.
EDIT : here is the requested stack trace
burnination [Android Application]
DalvikVM[localhost:8608]
Thread [<3> main] (Running)
Thread [<15> Binder Thread #3] (Running)
Thread [<13> Binder Thread #2] (Running)
Thread [<11> Binder Thread #1] (Running)
Thread [<17> Thread-9] (Suspended (exception NullPointerException))
GameThread.run() line: 53
source
share