0

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);

Taryn
  • 242,637
  • 56
  • 362
  • 405
  • Post the logcat stacktrace – nhaarman Nov 10 '13 at 18:05
  • '11-11 15:39:21.828: E/state(9953): NEW ' 11-11 15:39:25.262: E/AndroidRuntime(9953): FATAL EXCEPTION: Thread-562 11-11 15:39:25.262: E/AndroidRuntime(9953): java.lang.NullPointerException 11-11 15:39:25.262: E/AndroidRuntime(9953): at com.doggy.spinthebottle__elite.GameView.onDraw(GameView.java:141) 11-11 15:39:25.262: E/AndroidRuntime(9953): at com.doggy.spinthebottle__elite.GameLoopThread.run(GameLoopThread.java:30)' – user2680057 Nov 10 '13 at 20:42
  • above is what happens sometimes when pausing – user2680057 Nov 10 '13 at 20:49
  • when pause sometimes works, onresume crashes, there is too much log to post here, i will need to wait 8 hrs to post full log – user2680057 Nov 10 '13 at 20:50
  • What is at line 141 of GameView.java? – nhaarman Nov 10 '13 at 22:17

0 Answers0