Search code examples
androidadb

Error inflating class android.support.v4.view.PagerTabStrip


I am trying to run an application using the ViewPager item which is in the android.support.v4.view.ViewPager. This works great, so next I want to add the top items to it using the android.support.v4.view.PagerTabStrip. This throws an error when I want to run it on the emulator. The error is:

Binary XML file line #12: Error inflating class android.support.v4.view.PagerTabStrip

I've change the version of the emulators to google api's and no difference. I have also tried adding the user-lib to the manifest but that won't deploy it either. Anyone got any ideas?

I'm running it under Intellij as well not eclipse.

Ta

//Aditional info:

Logcat posted:

07-02 15:11:30.069: DEBUG/dalvikvm(626): GC_CONCURRENT freed 393K, 5% free 10796K/11335K, paused 18ms+24ms, total 95ms
07-02 15:11:30.129: ERROR/AndroidRuntime(626): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matjohnson/com.matjohnson.PageViewActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v4.view.PagerTabStrip
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v4.view.PagerTabStrip
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
        at android.app.Activity.setContentView(Activity.java:1867)
        at com.matjohnson.PageViewActivity.onCreate(PageViewActivity.java:32)
        at android.app.Activity.performCreate(Activity.java:5008)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
        ... 11 more
        Caused by: java.lang.ClassNotFoundException: android.support.v4.view.PagerTabStrip
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        at android.view.LayoutInflater.createView(LayoutInflater.java:552)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
        ... 22 more
07-02 15:11:30.209: WARN/ActivityManager(148): Force finishing activity com.matjohnson/.PageViewActivity
07-02 15:11:30.220: WARN/WindowManager(148): Failure taking screenshot for (328x583) to layer 21005
07-02 15:11:30.730: WARN/ActivityManager(148): Activity pause timeout for ActivityRecord{4163db60 com.matjohnson/.PageViewActivity}
07-02 15:11:41.420: WARN/ActivityManager(148): Activity destroy timeout for ActivityRecord{4163db60 com.matjohnson/.PageViewActivity}

//Edit - Added XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
        >

    <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        <android.support.v4.view.PagerTabStrip
                android:id="@+id/pager_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:background="#000"
                android:paddingBottom="4dp"
                android:paddingTop="4dp"
                android:textColor="#fff"/>
    </android.support.v4.view.ViewPager>

</RelativeLayout>

Solution

  • Ahhh, got it. What I have done is removed the maven version of the file and added it to the library directly from the androidsdk directory. There is probably a way of including it in the files but I can't work it out.

    It also needs to be a child of the ViewPager.

    Strange the viewpager works without this setting.