title: Failure delivering result ResultInfo{who=null, request=42, result=0, data=null} to activity
body: <p>Please help! When I run my program everything works fine when I go to the second activity, but when I go back to the first it comes up with an error. Here is the full error message:</p>
  
  <pre><code>              Process: com.example.android.lifeofcrime, PID: 2826
                java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=42, result=0, data=null} to activity {com.example.android.lifeofcrime/com.example.android.lifeofcrime.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Intent.getIntExtra(java.lang.String, int)' on a null object reference
                    at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
                    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
                    at android.app.ActivityThread.-wrap20(ActivityThread.java)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:154)
                    at android.app.ActivityThread.main(ActivityThread.java:6077)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Intent.getIntExtra(java.lang.String, int)' on a null object reference
                    at com.example.android.lifeofcrime.MainActivity.onActivityResult(MainActivity.java:63)
                    at android.app.Activity.dispatchActivityResult(Activity.java:6917)
                    at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
                    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096) 
                    at android.app.ActivityThread.-wrap20(ActivityThread.java) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:154) 
                    at android.app.ActivityThread.main(ActivityThread.java:6077) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
  </code></pre>
  
  <p>Here is the code for the first activity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  int test = 5;
  TextView money;
  int testReturn2 = 0;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      money = (TextView) findViewById (R.id.money);
      setupWorkButton();
  
  }
  
  public void setupWorkButton() {
      Button workButton = (Button) findViewById(R.id.workButton);
      workButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(MainActivity.this, workScreen.class);
              intent.putExtra("testing", test);
              startActivityForResult(intent, 42);
          }
      });
  }
  
  // Gets called when the activity started finishes
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-Generate method stub
      super.onActivityResult(requestCode, resultCode, data);
  
      switch (requestCode) {
          case 42:
              testReturn2 = data.getIntExtra("the answer", 0);
              money.setText("" + testReturn2);
              break;
  
  
      }
  }
  
  
  }
  </code></pre>
  
  <p>And here is the code for the second activity:</p>
  
  <pre><code>public class workScreen extends AppCompatActivity {
  int test;
  int testReturn = 0;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_work_screen);
      Intent intent = getIntent();
      test = intent.getIntExtra("testing", 0);
      TextView displayTest = (TextView) findViewById(R.id.intView);
      displayTest.setText("" + test);
      setupCharacterButton();
  
  
  }
  public void setupCharacterButton() {
      Button characterButton = (Button) findViewById(R.id.characterButton);
      characterButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              Intent intent = new Intent();
              testReturn = test * 2;
              intent.putExtra("the answer", testReturn);
              finish();
          }
      });
  }
  }
  </code></pre>