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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:49:45+00:00 2026-05-31T12:49:45+00:00

After leaving an activity and later returning to it using the onBackPressed() method I

  • 0

After leaving an activity and later returning to it using the onBackPressed() method I am getting a null pointer exception.

Activity A links to Activity B. When going back to A i am getting the following errors.

03-19 18:36:19.213: E/AndroidRuntime(441): FATAL EXCEPTION: main
03-19 18:36:19.213: E/AndroidRuntime(441): java.lang.NullPointerException
03-19 18:36:19.213: E/AndroidRuntime(441):  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
03-19 18:36:19.213: E/AndroidRuntime(441):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
03-19 18:36:19.213: E/AndroidRuntime(441):  at com.gurpswu.gurps.Player.open(Player.java:65)
03-19 18:36:19.213: E/AndroidRuntime(441):  at com.gurpswu.gurps.Home.refresh(Home.java:85)
03-19 18:36:19.213: E/AndroidRuntime(441):  at com.gurpswu.gurps.Crime.onBackPressed(Crime.java:295)

The code for Activity A is here:

package com.gurpswu.gurps;



 public class Home extends Activity {
Button crime, missions, bank,hospital, travel, bossVisit, weapons;
TextView name, city, energy, health, cash, rank,countdown;
public String characterName, cityName;
public int playerHealth,playerEnergy,playerRank,playerCash;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    referenceXML();
    hudSetup();
    listenerSetup();
    new CountDownTimer(30000, 1000) {

        public void onTick(long millisUntilFinished) {
            countdown.setText("seconds remaining: " + millisUntilFinished
                    / 1000);
        }

        public void onFinish() {
            countdown.setText("Energy replenished.");
            start();

        }
    }.start();

    if (playerHealth <= 0) {
        Intent death = new Intent(Home.this, Death.class);
        startActivity(death);
        finish();
    }

}

public void referenceXML() {
    countdown = (TextView) findViewById(R.id.tvCountdownTimer);
    crime = (Button) findViewById(R.id.bCrime);
    //gamble = (Button) findViewById(R.id.bGamble);
    bank = (Button) findViewById(R.id.bBank);
    hospital = (Button) findViewById(R.id.bHospital);
    bossVisit = (Button) findViewById(R.id.bBossVisit);
    travel = (Button) findViewById(R.id.bTravel);
    name = (TextView) findViewById(R.id.TextViewName);
    city = (TextView) findViewById(R.id.TextViewCity);
    weapons = (Button) findViewById(R.id.bWeapons);
    energy = (TextView) findViewById(R.id.TextViewEnergy);
    health = (TextView) findViewById(R.id.TextViewHealth);
    cash = (TextView) findViewById(R.id.TextViewCash);
    rank = (TextView) findViewById(R.id.TextViewRank);
}

public void hudSetup() {
    Player stats = new Player(this);
    stats.open();
    String playerName = stats.getStringField(stats.KEY_NAME);
    String playerCity = stats.getStringField(stats.KEY_CITY);
    playerHealth = stats.getIntField(stats.KEY_HEALTH);
    playerEnergy = stats.getIntField(stats.KEY_ENERGY);
    playerRank = stats.getIntField(stats.KEY_RANK);
    playerCash = stats.getIntField(stats.KEY_CASH);
    stats.close();
    name.setText("Name: " + playerName);
    city.setText("City: " + playerCity);
    energy.setText("Energy:" + playerEnergy);
    health.setText("Health:" + playerHealth);
    cash.setText("Cash: $" + playerCash);
    rank.setText("Rank:" + playerRank);

}



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

}

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

public void listenerSetup() {
    bank.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent openBank = new Intent(Home.this, Bank.class);
            startActivity(openBank);
        }
    });

    crime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub


            Intent openCrime = new Intent(Home.this, Crime.class);
            startActivity(openCrime);
        }
    });

    hospital.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent openHospital = new Intent(Home.this, Hospital.class);
            startActivity(openHospital);
        }
    });

    bossVisit.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent openBoss = new Intent(Home.this, VisitTheBoss.class);
            startActivity(openBoss);
            //finish();
        }
    });

    weapons.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent openWeapons = new Intent(Home.this, Weapons.class);
            startActivity(openWeapons);
        }
    });

    travel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent openTravel = new Intent(Home.this, Travel.class);
            startActivity(openTravel);
        }
    });

}

}

The onBackPressed code in activity B is here:

Home h = new Home();
        h.hudSetup();
        finish();
  • 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-31T12:49:47+00:00Added an answer on May 31, 2026 at 12:49 pm

    In home class you can set your ALL method.So this Example.May be it’s work for you.

    public void onResume() {
    super.onResume();
    referenceXML();
    hudSetup();
    listenerSetup();
    }
    

    or you can used startActivityForResult()

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

Sidebar

Related Questions

I just switched back to c++ after leaving it for awhile and I can't
I used onCheckedChanged method to handle the checkboxes.Its working well when i clicked.After leaving
I got back to Django after leaving it a few months ago, and came
After reading the Head First Design Patterns book and using a number of other
After the suggestion to use a library for my ajax needs I am going
After leaving an application idle for a long time it usually crashed when I
I've got a view controller that after leaving the stack, shows a memory leak
I have a method to process the rows from a datatable using multiple threads,
I have the following code (leaving out everything before and after to start with):
After reading this question , I was reminded of when I was taught Java

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.