i am just finishing up a small game i did, second one, based on code done by java4edu: http://www.edu4java.com/en/game/game0-en.html
however after my mods, i have run to a glitch where whenever i , resume, rotate screen, change the screen to (load from gallery), or anything that sends canvas to background; onresume, i get an error in which logcat always points to this: canvas.drawBitmap(bka, 0, 0, null);
i think though more importantly is that i need stop my gameloop thread at the approiate times, so that it refreshes and reloads the draw values, but idk, advice pls!!?
package com.doggy.__elite;
import android.annotation.SuppressLint;
import android.graphics.Canvas;
public class GameLoopThread extends Thread {
static final long FPS = 100;
private GameView view;
private boolean running = false;
public GameLoopThread(GameView view) {
this.view = view;
}
public void setRunning(boolean run) {
running = run;
}
@SuppressLint("WrongCall")
@Override
public void run() {
while (running) {
Canvas c = null;
try {
c = view.getHolder().lockCanvas();
synchronized (view.getHolder()) {
view.onDraw(c);
}
} finally {
if (c != null) {
view.getHolder().unlockCanvasAndPost(c);
}
}
}
}
}
line 141 is either: bka = Bitmap.createScaledBitmap(bka, Dwidtha, Dheighta, true); --or-- canvas.drawBitmap(bka, 0, 0, null); i found the on pause problem, i just had to add: public void onPause(Bundle savedInstanceState) { super.onPause(); } :)
this is what happens when resumeing:
11-24 12:16:12.538: E/AndroidRuntime(20772): FATAL EXCEPTION: main 11-24 12:16:12.538: E/AndroidRuntime(20772): java.lang.NullPointerException 11-24 12:16:12.538: E/AndroidRuntime(20772): at com.doggy.__elite.GameView$1.surfaceCreated(GameView.java:66) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.SurfaceView.updateWindow(SurfaceView.java:545) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:226) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.View.dispatchWindowVisibilityChanged(View.java:5851) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:951) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:951) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:951) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1038) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2583) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.os.Handler.dispatchMessage(Handler.java:99) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.os.Looper.loop(Looper.java:137) 11-24 12:16:12.538: E/AndroidRuntime(20772): at android.app.ActivityThread.main(ActivityThread.java:4508) 11-24 12:16:12.538: E/AndroidRuntime(20772): at java.lang.reflect.Method.invokeNative(Native Method) 11-24 12:16:12.538: E/AndroidRuntime(20772): at java.lang.reflect.Method.invoke(Method.java:511) 11-24 12:16:12.538: E/AndroidRuntime(20772): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809) 11-24 12:16:12.538: E/AndroidRuntime(20772): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) 11-24 12:16:12.538: E/AndroidRuntime(20772): at dalvik.system.NativeStart.main(Native Method)
line 66 is: gameLoopThread.setRunning(true);