title: Why is onCreate crashing Android App when I call onClick?
body: <p>I'm trying to load a new view when I push a Button. I have a viewPager and the button is on those views. When I call onClick my app never starts, it crashes before anything happens. I've  been trying to squash this bug for over a week and I think it's something very amateur. Please help a student programmer!</p>
  
  <pre><code>public class Main extends Activity {
  
      Button listButton;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.splash);
  
          SplashPager adapter = new SplashPager();
          ViewPager myPager = (ViewPager) findViewById(R.id.splashPager);
          myPager.setAdapter(adapter);
          myPager.setCurrentItem(0);
  
          listButtonListener();
      }
  
      public void listButtonListener() {
  
          listButton = (Button) findViewById(R.id.splashB);
          listButton.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
  
                  setContentView(R.layout.list_layout);
  
              }
  
          });
  
      }
  
  }
  </code></pre>
  
  <p>Log:</p>
  
  <pre><code>01-16 20:09:49.149: W/dalvikvm(29035): threadid=1: thread exiting with uncaught exception         (group=0x40207560)
  01-16 20:09:49.149: E/AndroidRuntime(29035): FATAL EXCEPTION: main
  01-16 20:09:49.149: E/AndroidRuntime(29035): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.survtest2/com.example.survtest2.Main}: java.lang.NullPointerException
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Handler.dispatchMessage(Handler.java:99)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Looper.loop(Looper.java:130)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.main(ActivityThread.java:3733)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invoke(Method.java:507)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:650)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at dalvik.system.NativeStart.main(Native Method)
  01-16 20:09:49.149: E/AndroidRuntime(29035): Caused by: java.lang.NullPointerException
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.listButtonListener(Main.java:36)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.onCreate(Main.java:30)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    ... 11 more
  01-16 20:09:49.149: E/AndroidRuntime(29035): [Blue Error Handler] Make Debugging Report file for main
  01-16 20:09:49.149: E/AndroidRuntime(29035): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.survtest2/com.example.survtest2.Main}: java.lang.NullPointerException
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Handler.dispatchMessage(Handler.java:99)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Looper.loop(Looper.java:130)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.main(ActivityThread.java:3733)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invoke(Method.java:507)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:650)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at dalvik.system.NativeStart.main(Native Method)
  01-16 20:09:49.149: E/AndroidRuntime(29035): Caused by: java.lang.NullPointerException
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.listButtonListener(Main.java:36)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.onCreate(Main.java:30)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
  01-16 20:09:49.149: E/AndroidRuntime(29035):    ... 11 more
  </code></pre>
  
  <p>splash.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/splashPager"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
  &lt;/android.support.v4.view.ViewPager&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>splash2.xml: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#000000"
      android:orientation="vertical" &gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:src="@drawable/intro__1" /&gt;
  
  &lt;Button
      android:id="@+id/splashB"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:layout_marginLeft="75dp"
      android:text="aaaaaaaaaaaaaaaaaa" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>ViewPager:</p>
  
  <pre><code>@Override
  public int getCount() {
      // TODO Auto-generated method stub
      return 4;
  }
  
  @Override
  public Object instantiateItem(View collection, int position) {
      LayoutInflater inflater = (LayoutInflater) collection.getContext()
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      int resId = 0;
      switch (position) {
  
      case 0:
          resId = R.layout.splash2;
          break;
      case 1:
          resId = R.layout.splash3;
          break;
      case 2:
          resId = R.layout.splash4;
          break;
      case 3:
          resId = R.layout.splash5;
          break;
  
      }
  
      View view = inflater.inflate(resId, null);
      ((ViewPager) collection).addView(view, 0);
      return view;
  
  }
  
  @Override
  public void destroyItem(View arg0, int arg1, Object arg2) {
      // TODO Auto-generated method stub
      ((ViewPager) arg0).removeView((View) arg2);
  }
  
  @Override
  public Parcelable saveState() {
      // TODO Auto-generated method stub
      return null;
  }
  
  @Override
  public boolean isViewFromObject(View arg0, Object arg1) {
      // TODO Auto-generated method stub
      return arg0 == ((View) arg1);
  }
  
  }
  </code></pre>