0

I'm trying to send my high score back to the main menu. Here are my intents. However, it just crashes when trying to get back to the main menu. My logcat is also below. Any tips would be great.

GameActivity

public void finish(){
      Intent returnIntent = new Intent();
      returnIntent.putExtra("GAME_SCORE",(gameView.getHitCount()));
      setResult(RESULT_OK, returnIntent);
      super.finish();
    }

MainMenu

protected void onActivityResult(int requestCode, int resultCode, Intent retIntent) {
    // Check which request we're responding to
    if (requestCode == SCORE_REQUEST_CODE) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            if (retIntent.hasExtra("GAME_SCORE")) {
                int scoreFromGame = retIntent.getExtras().getInt("GAME_SCORE");
                tvhiScore.setText(Integer.toString(scoreFromGame));
            }
        }   
    }

LogCat

  04-29 17:53:34.142: E/AndroidRuntime(1975): FATAL EXCEPTION: main
04-29 17:53:34.142: E/AndroidRuntime(1975): Process: cct.mad.lab, PID: 1975
04-29 17:53:34.142: E/AndroidRuntime(1975): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{cct.mad.lab/cct.mad.lab.MainMenu}: java.lang.NullPointerException
04-29 17:53:34.142: E/AndroidRuntime(1975):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
04-29 17:53:34.142: E/AndroidRuntime(1975):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
Saffa
  • 73
  • 9

2 Answers2

0

Either the value of tvhiScore or scoreFromGame is null. Add a breakpoint and debug this line and find which value is null.

Abdallah Alaraby
  • 2,222
  • 2
  • 18
  • 30
0

you don't need returnIntent. use getIntent() and put extras
start your game activity in main activity with startActivityForResult(intent,request code)

this could help: https://stackoverflow.com/a/10407371/3487232

Community
  • 1
  • 1
Amir
  • 1,250
  • 18
  • 22