title: Problems Passing Intent Extras to same activity ANDROID
body: <p>I am trying to pass intent extras to the same activity, but giving null pointer exception when clicking the page. I am trying to take an intent extra and use that to determine which layout file to load. </p>
  
  <pre><code>public class stuff extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Bundle extras = getIntent().getExtras();
          if(extras !=null){
              String value = extras.getString("name");
              if(value.equals("all")){
                  setContentView(R.layout.allnames);
              }
              if(value.equals("steve")){
                  setContentView(R.layout.steve);
              }
              if(value.equals("mark")){
                  setContentView(R.layout.mark);
              }
          }
  
          Button btnSteve = (Button) findViewById(R.id.btnSteve);
          btnSteve.setOnClickListener(new View.OnClickListener() {    
              public void onClick(View view) {
                  Intent myIntent = new Intent(view.getContext(), stuff.class);
                  myIntent.putExtra("name", "steve");
                  startActivityForResult(myIntent, 0);
      }
          });
      }
  }
  </code></pre>
  
  <p>Logcat is giving a </p>
  
  <blockquote>
    <p>Unable to start activity ComponentInfo() java.lang.NullPointerException </p>
  </blockquote>
  
  <p>when button is pressed. I am fairly new to Android development and I have searched online, and I am unable to find any information about passing intent extras back to same activity.</p>
  
  <p>Have declared this activity in the manifest as well.
          </p>
  
  <pre><code>        &lt;intent-filter&gt;
              &lt;action android:name=".stuff" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>This is the logcat errors:</p>
  
  <pre><code>06-20 09:00:48.817: E/AndroidRuntime(32586): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.appname.com/app.appname.com.Stuff}: java.lang.NullPointerException
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2174)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.ActivityThread.access$700(ActivityThread.java:141)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1267)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.os.Handler.dispatchMessage(Handler.java:99)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.os.Looper.loop(Looper.java:137)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.ActivityThread.main(ActivityThread.java:5059)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at java.lang.reflect.Method.invoke(Method.java:511)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at dalvik.system.NativeStart.main(Native Method)
  06-20 09:00:48.817: E/AndroidRuntime(32586): Caused by: java.lang.NullPointerException
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at app.appname.com.Stuff.onCreate(AllClasses.java:32)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.Activity.performCreate(Activity.java:5058)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  06-20 09:00:48.817: E/AndroidRuntime(32586):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
  </code></pre>
  
  <p>Any assistance would be appreciated.</p>
  
  <p>Thanks,</p>