title: Android : intent putExtra causing error
body: <p>I have 2 activities transferring a String variable from on to the other with a putExtra intent. I am using two buttons in the onclick method of the sender activity, one button retrieves a word from an array in another class and sends it to the recieving activity. The other button sends the String from an editText field. However, i am getting an error, any help appreciated. </p>
  
  <p>Sending class</p>
  
  <pre><code>public class TitleScreen extends Activity implements OnClickListener {
  
  Button onePlayer, twoPlayer, play;
  EditText inputWord;
  String b;
  
  
  WordDifficulties wordDiff = new WordDifficulties();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_title_screen);
  
      onePlayer = (Button) findViewById(R.id.OnePlayer);
      twoPlayer = (Button) findViewById(R.id.TwoPlayer);
      play = (Button) findViewById(R.id.Continue);
  
      inputWord = (EditText) findViewById(R.id.enterWord);
      inputWord.setVisibility(View.GONE);
      play.setVisibility(View.GONE);
  
      onePlayer.setOnClickListener(this);
      twoPlayer.setOnClickListener(this);
      play.setOnClickListener(this);
  
  }
  
  @Override
  public void onClick(View v) {
  
      if (v.getId() == R.id.OnePlayer) {
  
          Intent myIntent = new Intent(TitleScreen.this, MainActivity.class);
          myIntent.putExtra("gameWord", wordDiff.getRandomWord());
          startActivity(myIntent);
          finish();
  
      } else if (v.getId() == R.id.TwoPlayer) {
          onePlayer.setVisibility(View.GONE);
          twoPlayer.setVisibility(View.GONE);
          inputWord.setVisibility(View.VISIBLE);
          play.setVisibility(View.VISIBLE);
  
      } else if (v.getId() == R.id.Continue){
  
          // if no word is inputed then game will not start 
          if(inputWord.getText().toString().trim().length() == 0){
              Toast.makeText(getApplicationContext(), "Enter a word",
                      Toast.LENGTH_SHORT).show();
          } else{
              Intent myIntent = new Intent(TitleScreen.this, MainActivity.class);
              myIntent.putExtra("gameWord", inputWord.getText().toString());
              startActivity(myIntent);
              finish();
          }
      }
    }
  }
  </code></pre>
  
  <p>receiving activity within the onCreate method </p>
  
  <pre><code>    Intent myIntent = getIntent();
      secretWord = myIntent.getStringExtra("gameWord");
  </code></pre>
  
  <p>here is the logCat </p>
  
  <pre><code>Shutting down VM
  FATAL EXCEPTION: main
  Process: com.example.hunglikeanandroid, PID: 3431
  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.hunglikeanandroid/com.example.hunglikeanandroid.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
  atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
  at android.app.ActivityThread.access$800(ActivityThread.java:144)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5221)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
  at com.example.hunglikeanandroid.MainActivity.&lt;init&gt;(MainActivity.java:35)
  at java.lang.reflect.Constructor.newInstance(Native Method)
  at java.lang.Class.newInstance(Class.java:1572)
  at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
  </code></pre>