InflateException in ViewPager
<p>I have implemented a ViewPager with 4 fragments. But for some reason it is throwing an <a href="https://drive.google.com/open?id=0B_WFd1NrbiglX2Z3eWhuUUhSVFE" rel="nofollow">error</a> when I swipe to the 3rd fragment.</p>

<p>The problem is I am getting this error only when I run the code in my emulator(Lollipop) the app runs fine in my device(Kitkat).</p>

<p>The XML file of the fragment is</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"&gt;
&lt;android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity"
    android:id="@+id/linearlayout1"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"&gt;
   &lt;!--        android:background="#616161"--&gt;
    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/learn"
        android:textSize="25sp"
        app:layout_marginTopPercent="3%"
        android:textColor="#ffffff"
        android:text="Power of Foresight" /&gt;
    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_below="@id/learn"
        app:layout_marginTopPercent="5%"
        android:textSize="20sp"
        android:textColor="#ffffff"
        android:textAlignment="center"
        android:text="With our advanced algorithms we predict the questions that could appear in the next test. "/&gt;
    &lt;ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView3"
        android:gravity="center"
        android:src="@drawable/no_background2"/&gt;
&lt;/android.support.percent.PercentRelativeLayout&gt;
&lt;/android.support.percent.PercentRelativeLayout&gt;
</code></pre>

<p>The other two fragments are also similar the only change is in the text and the image embedded.</p>

<p>The java file of the fragment is </p>

<pre><code>public class EntryPage1 extends Fragment {
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstances){

    return inflater.inflate(R.layout.entrypage_1,container,false);
   }
}
</code></pre>

<p>The ViewPager adapter is as follows</p>

<pre><code>public class EntryPageHolder1 extends FragmentActivity{
private PagerAdapter mPagerAdapter;
int[] pageColors = new int[]{Color.parseColor("#3367D6"),Color.parseColor("#00BCD4"),Color.parseColor("#F4B400"),Color.TRANSPARENT};

int currentColor = pageColors[0];
ValueAnimator colorAnimation;
View animatedColorView;
ViewPager pager;
@Override
public void onCreate(Bundle SavedInstances){
    super.onCreate(SavedInstances);
    super.setContentView(R.layout.activity_entrypage_holder);
    animatedColorView=(View)findViewById(R.id.animated_color_view);
    this.initialisepaging();
    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    ActionBar actionBar = getActionBar();
    actionBar.hide();
}
public void initialisepaging(){
    List&lt;Fragment&gt; fragments = new Vector&lt;Fragment&gt;();
    fragments.add(Fragment.instantiate(this, EntryPage2.class.getName()));
    fragments.add(Fragment.instantiate(this, EntryPage3.class.getName()));
    fragments.add(Fragment.instantiate(this, EntryPage1.class.getName()));
    fragments.add(Fragment.instantiate(this, EntryPage4.class.getName()));
    this.mPagerAdapter  = new PagerAdapter(super.getSupportFragmentManager(), fragments);
    pager = (ViewPager)super.findViewById(R.id.viewpager);
    pager.setAdapter(this.mPagerAdapter);
    pager.setPageTransformer(true, new DefaultTransformer());
    animateToColor(pageColors[0]);
    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            //animateToColor(pageColors[position]);
        }

        @Override
        public void onPageSelected(int position) {
            //Toast.makeText(getApplicationContext(),"Listener executing",Toast.LENGTH_SHORT).show();
            animateToColor(pageColors[position]);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
public void animateToColor(int colorTo) {
    if (colorAnimation != null) {
        colorAnimation.cancel();
    }
    colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), currentColor, colorTo);
    colorAnimation.setDuration(150); // milliseconds
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            currentColor = (int) animator.getAnimatedValue();
            animatedColorView.setBackgroundColor(currentColor);
        }

    });
    colorAnimation.start();
}
}
</code></pre>

<p>The error log is as follows</p>

<pre><code>     android.view.InflateException: Binary XML file line #40: Binary XML file line #40: Error inflating class &lt;unknown&gt;
            at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at com.spintum.preexam.EntryPage1.onCreateView(EntryPage1.java:19)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:490)
            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:1105)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
            at android.support.v4.view.ViewPager$3.run(ViewPager.java:250)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
            at android.view.Choreographer.doCallbacks(Choreographer.java:670)
            at android.view.Choreographer.doFrame(Choreographer.java:603)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: android.view.InflateException: Binary XML file line #40: Error inflating class &lt;unknown&gt;
            at android.view.LayoutInflater.createView(LayoutInflater.java:645)
            at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at com.spintum.preexam.EntryPage1.onCreateView(EntryPage1.java:19)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:490)
            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:1105)
                at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
            at android.support.v4.view.ViewPager$3.run(ViewPager.java:250)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
            at android.view.Choreographer.doCallbacks(Choreographer.java:670)
            at android.view.Choreographer.doFrame(Choreographer.java:603)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at android.view.LayoutInflater.createView(LayoutInflater.java:619)
            at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at com.spintum.preexam.EntryPage1.onCreateView(EntryPage1.java:19)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:490)
            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:1105)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
            at android.support.v4.view.ViewPager$3.run(ViewPager.java:250)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
            at android.view.Choreographer.doCallbacks(Choreographer.java:670)
            at android.view.Choreographer.doFrame(Choreographer.java:603)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.OutOfMemoryError: Failed to allocate a 33249648 byte allocation with 4194304 free bytes and 20MB until OOM
            at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
            at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
            at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
            at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
            at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
            at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
            at android.content.res.Resources.loadDrawable(Resources.java:2540)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:870)


 at android.widget.ImageView.&lt;init&gt;(ImageView.java:152)
        at android.widget.ImageView.&lt;init&gt;(ImageView.java:140)
        at android.widget.ImageView.&lt;init&gt;(ImageView.java:136)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at android.view.LayoutInflater.createView(LayoutInflater.java:619)
            at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at com.spintum.preexam.EntryPage1.onCreateView(EntryPage1.java:19)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:490)
            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:1105)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
            at android.support.v4.view.ViewPager$3.run(ViewPager.java:250)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
            at android.view.Choreographer.doCallbacks(Choreographer.java:670)
            at android.view.Choreographer.doFrame(Choreographer.java:603)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)

            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)nter code here
</code></pre>

<p>What would be the cause of this error and why does it run correctly on one device and not on another?</p>