0
@Override
public void run() {
    Canvas canvas;
        while (running) {
        canvas = null;
        try {
            canvas = this.surfaceHolder.lockCanvas();
            synchronized (surfaceHolder) {
                this.gamePanel.update();
                this.gamePanel.render(canvas);              
            }
        } finally {


            if (!canvas.equals(null)) { // error is here.
                surfaceHolder.unlockCanvasAndPost(canvas);
            }
        }   
    }
}
codeMagic
  • 44,549
  • 13
  • 77
  • 93
zahra
  • 1
  • 1
  • You really should post some explanation and a question instead of simply pasting code with an error message – codeMagic Jan 25 '16 at 14:15
  • This is what i get in the LogCat. 01-25 14:25:54.628: E/AndroidRuntime(3357): FATAL EXCEPTION: Thread-197 01-25 14:25:54.628: E/AndroidRuntime(3357): java.lang.NullPointerException 01-25 14:25:54.628: E/AndroidRuntime(3357): at com.zm.atz.Maingame_m1.render(Maingame_m1.java:64) 01-25 14:25:54.628: E/AndroidRuntime(3357): at com.zm.atz.Mainthread_m1.run(Mainthread_m1.java:31) – zahra Jan 25 '16 at 14:16
  • You get more than that. Anyway, you want ` if(canvas != null)` because right now you might be calling a method on a null object. And please don't post your logcat in comments...it's so hard to read. Instead, use the edit button below the tags in your question to add it to your post. – codeMagic Jan 25 '16 at 14:17
  • Possible duplicate of [How to solve FATAL EXCEPTION: Thread-11](http://stackoverflow.com/questions/12709799/how-to-solve-fatal-exception-thread-11) – user1140237 Jan 25 '16 at 14:24

1 Answers1

1

If there is any error executing

canvas = this.surfaceHolder.lockCanvas();

then canvas will be null. This is what I suspect what's going on here.

Change

if (!canvas.equals(null)) {

to

if (canvas != null) {
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57