title: NullPointerException and app crashes when using .getInt (Android)
body: <p>I'm using an intent and getIntent on my Android app but it crashes in the emulator. Logcat indicates that my problem it's a NullPointerException but since yesterday I just can't find the solution for this problem.</p>
  
  <p>Here is my Logcat:</p>
  
  <pre><code>10-05 20:27:12.053: E/AndroidRuntime(246): Uncaught handler: thread main exiting due to uncaught exception
  10-05 20:27:12.063: E/AndroidRuntime(246): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.Tonos/com.example.Tonos.TonosSet}: java.lang.NullPointerException
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.os.Handler.dispatchMessage(Handler.java:99)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.os.Looper.loop(Looper.java:123)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.app.ActivityThread.main(ActivityThread.java:4363)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at java.lang.reflect.Method.invokeNative(Native Method)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at java.lang.reflect.Method.invoke(Method.java:521)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at dalvik.system.NativeStart.main(Native Method)
  10-05 20:27:12.063: E/AndroidRuntime(246): Caused by: java.lang.NullPointerException
  10-05 20:27:12.063: E/AndroidRuntime(246):  at com.example.Tonos.TonosSet.onCreate(TonosSet.java:21)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  10-05 20:27:12.063: E/AndroidRuntime(246):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
  10-05 20:27:12.063: E/AndroidRuntime(246):  ... 11 more
  </code></pre>
  
  <p>This is my "TonosSet.java":</p>
  
  <pre><code>package com.example.Tonos;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  
  public class TonosSet extends Activity {
  /**
   * @see android.app.Activity#onCreate(Bundle)
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.tonos_set);
  
      Intent i = getIntent();
      int position = i.getExtras().getInt("id");
  
      ImageView imageView = (ImageView) findViewById(R.id.full_image_view2);
      TextView textView1 = (TextView)findViewById(R.id.namesong);
      TextView textView2 = (TextView)findViewById(R.id.artist);
  
      switch (position){
      case 0:        
          imageView.setImageResource(R.drawable.pico);
  
          textView1.setText("Tone1");
          textView2.setText("Someone");        
      break;
  
      case 1:        
          imageView.setImageResource(R.drawable.pict);
  
          textView1.setText("Tone2");
          textView2.setText("Someone");           
      break;
  
      }
  
  
  }
  }
  </code></pre>
  
  <p>And here is the part of code that creates the Intent "i" (Tonos.java):</p>
  
  <pre><code>....            
  maListViewPerso.setAdapter(mSchedule);
  
      maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
              @Override
          @SuppressWarnings("unchecked")
          public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id){
                  HashMap&lt;String, String&gt; map = (HashMap&lt;String, String&gt;) maListViewPerso.getItemAtPosition(position);
  
                  Toast.makeText(Tonos.this, "" + position, Toast.LENGTH_SHORT).show();
  
                  Intent tonosset = new Intent(Tonos.this, TonosSet.class);
                  startActivity(tonosset);
  
                  Intent i = new Intent(getApplicationContext(), TonosSet.class);
  
                  i.putExtra("id", position);
                  startActivity(i);
  
              }
  
  
      });
  
  }
  }
  </code></pre>
  
  <p>Thanks a lot guys! =)</p>