title: Unable to get string from a Bundle
body: <p>I created a new Activity once a Login is successful. But when I start the app, the app crash within 5 seconds with the message </p>
  
  <blockquote>
    <p><code>Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference</code></p>
  </blockquote>
  
  <p>Error is coming from this </p>
  
  <pre><code>name.setText(" "+bundle.getString("name"));
  </code></pre>
  
  <hr>
  
  <pre><code>public class LoginActivity extends Activity {
  
      public ImageView bgLogo;
  
      Button login_button;
      EditText Username, Password;
      String username, password;
      String login_url = "http://192.168.0.19/login.php";
      AlertDialog.Builder builder;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          requestWindowFeature(Window.FEATURE_NO_TITLE); // Enlever la barre bleue
          setContentView(R.layout.activity_login);
  
          initExit ();
  
          builder = new AlertDialog.Builder(LoginActivity.this);
          login_button = (Button) findViewById(R.id.bLogin);
          Username = (EditText) findViewById(R.id.etUsername);
          Password = (EditText) findViewById(R.id.etPassword);
  
          login_button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  username = Username.getText().toString();
                  password = Password.getText().toString();
  
                  if (username.equals("") || password.equals("")) {
  
                      builder.setTitle("Mince une erreur...");
                      displayAlert("Veuillez entrer un username et un mot de passe correct...");
                  }
  
                  else {
  
                      StringRequest stringRequest = new StringRequest(Request.Method.POST, login_url,
                              new Response.Listener&lt;String&gt;() {
                                  @Override
                                  public void onResponse(String response) {
  
                                      JSONArray jsonArray = null;
                                      try {
                                          jsonArray = new JSONArray(response);
                                          JSONObject jsonObject = jsonArray.getJSONObject(0);
                                          String code = jsonObject.getString("code");
  
                                          if (code.equals("login_failed")) {
  
                                              builder.setTitle("Erreur d'authentification");
                                              displayAlert(jsonObject.getString("message"));
                                          }
  
                                          else {
  
                                              Intent intent = new Intent (LoginActivity.this, UserAreaActivity.class);
                                              Bundle bundle = new Bundle();
                                              bundle.putString("name", jsonObject.getString("name"));
                                              intent.putExtras(bundle);
                                              startActivity(intent);
                                          }
                                      } catch (JSONException e) {
                                          e.printStackTrace();
                                      }
  
                                  }
                              }, new Response.ErrorListener() {
  
                          @Override
                          public void onErrorResponse(VolleyError error) {
  
                              Toast.makeText(LoginActivity.this, "Erreur", Toast.LENGTH_LONG).show();
                              error.printStackTrace();
  
                          }
                      })
                      {
                          @Override
                          protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
  
                              Map &lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                              params.put("user_name", username);
                              params.put("password", password);
                              return params;
                          }
                      };
  
                      MySingleton.getInstance(LoginActivity.this).addToRequestque(stringRequest);
                  }
              }
          });
      }
  
      private void initExit() {
  
          bgLogo = (ImageView) findViewById(R.id.bgLogo1);
          bgLogo.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick (View v) {
  
                  Intent intent = new Intent (LoginActivity.this, MainActivity.class);
                  startActivity(intent);
              }
          });
      }
  
      public void displayAlert (String message) {
  
          builder.setMessage(message);
          builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  Username.setText("");
                  Password.setText("");
              }
          });
  
          AlertDialog alertDialog = builder.create();
          alertDialog.show();
      }
  
      @Override
      public void onBackPressed() {
          // do nothing.
          Intent intent = new Intent(LoginActivity.this, MainActivity.class);
          startActivity(intent);
          return;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class UserAreaActivity extends Activity {
  
      public ImageView bgNet;
      public ImageView bgChat;
      public ImageView bgStats;
      public ImageView bgGo;
      public Button bLogout;
  
      TextView name;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          requestWindowFeature(Window.FEATURE_NO_TITLE); // Enlever la barre bleue
          setContentView(R.layout.activity_user_area);
  
          name = (TextView) findViewById(R.id.name);
  
          Bundle bundle = getIntent().getExtras();
          name.setText(" "+bundle.getString("name"));
  
          initGoHome ();
          initPlay ();
          initGoStats ();
          initGoChat ();
          buttonLogout ();
      }
  
      @Override
      public void onBackPressed() {
          return;
      }
  
      private void initGoHome () {
  
          bgNet = (ImageView) findViewById(R.id.bgNet);
          bgNet.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick (View v) {
  
                  Intent intent = new Intent (UserAreaActivity.this, HomeActivity.class);
                  startActivity(intent);
              }
          });
      }
  
      private void initPlay () {
  
          bgGo = (ImageView) findViewById(R.id.bgGo);
          bgGo.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick (View v) {
  
                  Intent intent = new Intent (UserAreaActivity.this, PlayActivity.class);
                  startActivity(intent);
              }
          });
      }
  
      private void initGoStats () {
  
          bgStats = (ImageView) findViewById(R.id.bgStats);
          bgStats.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick (View v) {
  
                  Intent intent = new Intent (UserAreaActivity.this, StatsActivity.class);
                  startActivity(intent);
              }
          });
      }
  
      private void initGoChat () {
  
          bgChat = (ImageView) findViewById(R.id.bgChat);
          bgChat.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick (View v) {
  
                  Intent intent = new Intent (UserAreaActivity.this, ChatActivity.class);
                  startActivity(intent);
              }
          });
      }
  
      private void buttonLogout () {
  
          bLogout = (Button) findViewById(R.id.bLogout);
          bLogout.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick (View v) {
  
                  Intent intent = new Intent (UserAreaActivity.this, MainActivity.class);
                  startActivity(intent);
              }
          });
      }
  }
  </code></pre>