title: Android App Unfortunately App has stopped
body: <p>I am still learning Android programming, had this app and its giving me the unfortunately stopped error.</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>package com.nyt.ilm.ilmsarf;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  
  public class MainActivity extends FragmentActivity {
  
      ViewPager viewpager;
      @Override
      protected void onCreate(Bundle arg0) {
          // TODO Auto-generated method stub
          super.onCreate(arg0);
          setContentView(R.layout.activity_main);
          viewpager = (ViewPager) findViewById(R.id.pager);
          viewpager.setAdapter(new MyPageAdapter(getSupportFragmentManager()));
      }
  
  }
  
  class MyPageAdapter extends FragmentPagerAdapter {
  
      public MyPageAdapter(FragmentManager fm) {
          super(fm);
          // TODO Auto-generated constructor stub
      }
  
      @Override
      public Fragment getItem(int arg0) {
          // TODO Auto-generated method stub
          Fragment fr=null;
          if (arg0==0)
                  fr=new P1();
          if(arg0==1)
              fr=new P2();
          if(arg0==2)
              fr=new P3();
          return fr;
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return 3;
      }
  
  }
  </code></pre>
  
  <p><strong>P1.java (Fragment)</strong></p>
  
  <pre><code> package com.nyt.ilm.ilmsarf;
  
      import android.app.Activity;
      import android.net.Uri;
      import android.os.Bundle;
      import android.support.v4.app.Fragment;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
  
      public class P1 extends Fragment {
  
          private OnFragmentInteractionListener mListener;
  
          public P1() {
              // Required empty public constructor
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              // Inflate the layout for this fragment
              return inflater.inflate(R.layout.p1, container, false);
          }
  
          // TODO: Rename method, update argument and hook method into UI event
          public void onButtonPressed(Uri uri) {
              if (mListener != null) {
                  mListener.onFragmentInteraction(uri);
              }
          }
  
          @Override
          public void onAttach(Activity activity) {
              super.onAttach(activity);
              try {
                  mListener = (OnFragmentInteractionListener) activity;
              } catch (ClassCastException e) {
                  throw new ClassCastException(activity.toString()
                          + " must implement OnFragmentInteractionListener");
              }
          }
  
          @Override
          public void onDetach() {
              super.onDetach();
              mListener = null;
          }
  
          /**
           * This interface must be implemented by activities that contain this
           * fragment to allow an interaction in this fragment to be communicated to
           * the activity and potentially other fragments contained in that activity.
           * &lt;p&gt;
           * See the Android Training lesson &lt;a href=
           * "http://developer.android.com/training/basics/fragments/communicating.html"
           * &gt;Communicating with Other Fragments&lt;/a&gt; for more information.
           */
          public interface OnFragmentInteractionListener {
              // TODO: Update argument type and name
              public void onFragmentInteraction(Uri uri);
          }
  
      }
  </code></pre>
  
  <p><strong>P1.xml</strong></p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.nyt.ilm.ilmsarf.P1" &gt;
  
      &lt;!-- TODO: Update blank fragment layout --&gt;
  
      &lt;ImageView
          android:id="@+id/imageView1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:src="@drawable/sarf01" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p><strong>and the activity.xml is</strong></p>
  
  <pre><code> &lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/pager"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity" /&gt;
  </code></pre>
  
  <p><strong>AndroidManifest.xml is</strong> </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.nyt.ilm.ilmsarf"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="17" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.nyt.ilm.ilmsarf.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
           &lt;activity android:name="com.nyt.ilm.ilmsarf.P1" /&gt;
               &lt;activity android:name="com.nyt.ilm.ilmsarf.P2" /&gt;
                &lt;activity android:name="com.nyt.ilm.ilmsarf.P3" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>P2, P3 are as p1.xml and P1.java</strong></p>
  
  <p>plz help.
  Thanks in advance.</p>