title: Android-null pointer exception after onResume in game loop
body: <p>I am working on an android game.I was the facing the same issue as <a href="https://stackoverflow.com/questions/5318847/android-crash-when-app-is-closed-and-reopened/5319629#5319629.">here</a></p>
  
  <p>I tried the wait and notify all solution as shown over there.But as soon the app resumes i get Null pointer exception.
  Here is the log cat info.</p>
  
  <pre><code>INFO/System.out(8166): on resume
  INFO/System.out(8166): !!!! IN THE GAME RESUME ---- &gt;&gt;&gt; 
  INFO/System.out(8166):  SURFACE CREATED
  INFO/System.out(8166): thread on resume
  INFO/System.out(8166): in thread game pause=true
  WARN/dalvikvm(8166): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
  ERROR/AndroidRuntime(8166): FATAL EXCEPTION: Thread-11
  ERROR/AndroidRuntime(8166): java.lang.NullPointerException
  ERROR/AndroidRuntime(8166):     at com.org.GummyBlast.GameView.onDraw(GameView.java:442)
  ERROR/AndroidRuntime(8166):     at com.org.GummyBlast.GameLoopThread.run(GameLoopThread.java:88)
  </code></pre>
  
  <p>The code inside onSurfaceCreated and onSurfaceDestroyed</p>
  
  <pre><code>private void init() {
  
      gameLoopThread = new GameLoopThread(this);
      holder = getHolder();
      holder.addCallback(new SurfaceHolder.Callback() {
  
          @Override
          public void surfaceDestroyed(SurfaceHolder holder) {
              System.out.println(" SURFACE DESTROYED");
  
              nullImages();
              boolean retry = true;
  
              //gameLoopThread.setRunning(false);
              if(!mGameIsRunning){
              while (retry) {
                  try {
                      gameLoopThread.join();
  
                      retry = false;
                  } catch (InterruptedException e) {
                  }
              }
          }
  
  
      }
  
          @Override
          public void surfaceCreated(SurfaceHolder holder) {
              System.out.println(" SURFACE CREATED");
              Log.d("surface create", "SURFACE CREATED");
  
              /*gameLoopThread.setRunning(true);
  
              gameLoopThread.start();*/
              start(holder);
  
          }
  
          public void start(SurfaceHolder holder) {
              if (!mGameIsRunning) {
  
                  gameLoopThread.setRunning(true);
                  gameLoopThread.start();
                  mGameIsRunning = true;
              } else {
  
                  gameLoopThread.onResume();
              }
          }
  </code></pre>
  
  <p>Code in my GameThread class</p>
  
  <pre><code>public class GameLoopThread extends Thread {
  static final long FPS = 10;
  private  GameView view;
  public static boolean running = false;
  public static boolean run = true;
  public static boolean game_pause=true;
   private static Object mPauseLock;
   private boolean mFinished=false;
   long ticksPS = 1000 / FPS;
      long startTime;
      long sleepTime;
   SurfaceHolder holder;
  public GameLoopThread(GameView view) {
       mPauseLock = new Object();
  
      this.view = view;
  }
  
  public GameLoopThread() {
       mPauseLock = new Object();
  }
  
  
  public void setRunning(boolean run) {
      running = run;
  }
  
  
  
  
  @Override
  public void run() {
      while (running) {
          // Do stuff.
          System.out.println("in thread game pause="+Boolean.toString(game_pause));
          if (game_pause == true) {
              Canvas c = null;
              startTime = System.currentTimeMillis();
              try {
                  c = view.getHolder().lockCanvas();
                  synchronized (view.getHolder()) {
                      view.onDraw(c);
  
                  }
  
              } finally {
                  if (c != null) {
                      view.getHolder().unlockCanvasAndPost(c);
                  }
              }
  
              sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
              try {
                  if (sleepTime &gt; 0)
                      sleep(sleepTime);
                  else
                      sleep(10);
              } catch (Exception e) {
                  System.out.println("Error in game loop thread "+ e.getMessage());
  
              }
          }
          else{
          synchronized (mPauseLock) {
              while (game_pause==false) {
                  try {
                      mPauseLock.wait();
                  } catch (InterruptedException e) {
                  }
              }
          }
          } 
      }
  }
  public void onPause() {
      synchronized (mPauseLock) {
          game_pause = false;
          System.out.println("thread on pause");
      }
  }
  
  /**
   * Call this on resume.
   */
  public void onResume() {
      synchronized (mPauseLock) {
          game_pause = true;
          mPauseLock.notifyAll();
          System.out.println("thread on resume");
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Activity class onPause </p>
  
  <pre><code>@Override
  public void onPause() {
      super.onPause();
  
      System.out.println(" --- IN GAME PAUSE ---");
  
  
          gameLoopThread = new GameLoopThread();
          gameLoopThread.onPause();
  
        }
  </code></pre>
  
  <p>how to maintain the state of the game in onResume? 
  Thanks </p>