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 6103079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:41:15+00:00 2026-05-23T13:41:15+00:00

I’m writing a game on Android and this issue has stumped me. I overrode

  • 0

I’m writing a game on Android and this issue has stumped me. I overrode onPause() to enable the game to save its data to internal storage when it is not visible anymore. It works correctly until three or four times of pressing back or home. I get this instead:

Thread [<1> main] (Suspended (exception NullPointerException))  
    Main.onPause() line: 127    
    Main(Activity).performPause() line: 3842    
    Instrumentation.callActivityOnPause(Activity) line: 1190    
    ActivityThread.performPauseActivity(ActivityThread$ActivityRecord, boolean, boolean) line: 3335 
    ActivityThread.performPauseActivity(IBinder, boolean, boolean) line: 3305   
    ActivityThread.handlePauseActivity(IBinder, boolean, boolean, int) line: 3288   
    ActivityThread.access$2500(ActivityThread, IBinder, boolean, boolean, int) line: 125    
    BinderProxy(ActivityThread$H).handleMessage(Message) line: 2044 
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4627    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 521  
    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    ZygoteInit.main(String[]) line: 626 
    NativeStart.main(String[]) line: not available [native method]

The debugger states it blows up on this:

@Override
public void onPause() {
    super.onPause();
    Data data = game.writeProtoBuf(); // NullPointerException
    try {
    //IO stuff

writeProtoBuf doesn’t actually write anything but is just a method to retrieve the game data and put it into the Data object. The debugger shows that game is null, but I don’t see how that is possible when I can interact with the game correctly before closing it down. :/

  • 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-23T13:41:16+00:00Added an answer on May 23, 2026 at 1:41 pm

    After much teeth-grinding, I think I have worked out the issue. I was assuming that the game instance would persist when changing activities. It doesn’t, so that was why Android kept throwing up Nullpointer. I would start up the app, exit it (which causes it to save to internal storage), and then when I tried to save it again, it wouldn’t work.

    I fixed this by turning Game into a singleton, thereby preserving its state across activities. I admit I don’t really understand why this works or how it works, but it works. If I sound really blur and confused, it’s because I am. 😛

    Inspiration for the fix came from here.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.