title: custom view pager :Error inflating class android.support.v4.app.ViewPager
body: <p>hi i want to make custom viewpager, in that i am loading 2 images in each viewpage</p>
  
  <p>my java code is below</p>
  
  <p>This is the mainactivity.java</p>
  
  <pre><code>   public class MainActivity extends Activity {
  
  ViewPager viewPager;
  int img1[] = { R.drawable.ic_launcher, R.drawable.ic_launcher,
          R.drawable.ic_launcher, R.drawable.ic_launcher };
  
  int img2[] = { R.drawable.ic_launcher, R.drawable.ic_launcher,
          R.drawable.ic_launcher, R.drawable.ic_launcher };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      viewPager = (ViewPager) findViewById(R.id.viewPager);
  
      viewPager
              .setAdapter(new ViewPagerAdapter(MainActivity.this, img1, img2));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>now ViewPagerAdapter class</p>
  
  <pre><code> public class ViewPagerAdapter extends PagerAdapter {
  
  Context context;
  int[] img1;
  int[] img2;
  
  LayoutInflater inflater;
  
  public ViewPagerAdapter(Context context, int[] img1, int[] img2) {
      this.context = context;
      this.img1 = img1;
      this.img2 = img2;
  }
  
  @Override
  public boolean isViewFromObject(View view, Object object) {
      return view == ((RelativeLayout) object);
  }
  
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
  
      inflater = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View itemView = inflater.inflate(R.layout.pager_item, container, false);
  
      // define resources of corresponding image views here.
      // finally bind images to the imageviews.
  
      ((ViewPager) container).addView(itemView);
  
      return itemView;
  }
  
  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {
      ((ViewPager) container).removeView((LinearLayout) object);
  
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return img1.length;
  }
  
  @Override
  public void startUpdate(ViewGroup container) {
      // TODO Auto-generated method stub
      super.startUpdate(container);
  
  }
  
  }
  </code></pre>
  
  <p>the activity_main.xml is </p>
  
  <pre><code>&lt;android.support.v4.app.ViewPager
      android:id="@+id/viewPager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:text="@string/hello_world" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>but everytime i am getting an error like </p>
  
  <pre><code>     Binary XML file line #11: Error inflating class android.support.v4.app.ViewPager
  </code></pre>
  
  <p>the logcat is below</p>
  
  <pre><code>     01-09 11:29:31.853: E/AndroidRuntime(22506): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.viewpagerdemo/com.example.viewpagerdemo.MainActivity}:      android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v4.app.ViewPager
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.os.Handler.dispatchMessage(Handler.java:107)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.os.Looper.loop(Looper.java:194)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.ActivityThread.main(ActivityThread.java:5371)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at java.lang.reflect.Method.invoke(Method.java:525)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at dalvik.system.NativeStart.main(Native Method)
  01-09 11:29:31.853: E/AndroidRuntime(22506): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v4.app.ViewPager
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.Activity.setContentView(Activity.java:1881)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at com.example.viewpagerdemo.MainActivity.onCreate(MainActivity.java:20)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.Activity.performCreate(Activity.java:5122)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    ... 11 more
  01-09 11:29:31.853: E/AndroidRuntime(22506): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.app.ViewPager" on path: DexPathList[[zip file "/data/app/com.example.viewpagerdemo-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.viewpagerdemo-1, /vendor/lib, /system/lib]]
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at   java.lang.ClassLoader.loadClass(ClassLoader.java:461)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
  01-09 11:29:31.853: E/AndroidRuntime(22506):    ... 21 more
  </code></pre>