Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:54:19+00:00 2026-05-27T04:54:19+00:00

I am working on an android game.I was the facing the same issue as

  • 0

I am working on an android game.I was the facing the same issue as here

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.

INFO/System.out(8166): on resume
INFO/System.out(8166): !!!! IN THE GAME RESUME ---- >>> 
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)

The code inside onSurfaceCreated and onSurfaceDestroyed

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 in my GameThread class

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

}

Activity class onPause

@Override
public void onPause() {
    super.onPause();

    System.out.println(" --- IN GAME PAUSE ---");


        gameLoopThread = new GameLoopThread();
        gameLoopThread.onPause();

      }

how to maintain the state of the game in onResume?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:54:20+00:00Added an answer on May 27, 2026 at 4:54 am

    Maybe you need to call onResume() on your superclass:

    public void onResume() {
         super.onResume();
    }
    

    Hope this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working in a game for Android, but is the same game that exist
I'm new to android game development. I currently working on a simple android app
I am working on a cross-platform mobile game for Android and iOS devices. I
Ahoy, I'm working on an OpenGL ES based game for Android using the NDK.
I'm working on an Android game with Eclipse, suddenly appears lots of errors in
I am working on a game for android right now. It is a game
Ive been working on multiplayer android game that sends locally stored data to a
So I am working on a simple android Tetris type game. On the first
I'm working on a Mobile Game for several platforms ( Android, iOS, and some
Hi I am new to android development and I'm working on a game. Right

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.