扩展类android.support.v4.view.PagerTabStrip时出错

时间:2013-07-02 08:22:59

标签: android adb

我正在尝试使用android.support.v4.view.ViewPager中的ViewPager项运行应用程序。这很好用,接下来我想使用android.support.v4.view.PagerTabStrip为它添加顶级项目。当我想在模拟器上运行它时会抛出一个错误。错误是:

二进制XML文件行#12:错误膨胀类android.support.v4.view.PagerTabStrip

我已将模拟器的版本更改为google api,并没有区别。我也尝试将user-lib添加到清单中,但也不会部署它。有人有任何想法吗?

我在Intellij下运行它而不是eclipse。

TA

//有条件的信息:

Logcat发布:

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}

//编辑 - 添加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>

2 个答案:

答案 0 :(得分:1)

啊,嗯,明白了。我所做的是删除文件的maven版本,并直接从androidsdk目录将其添加到库中。可能有一种方法可以将其包含在文件中,但我无法解决它。

它还需要是ViewPager的孩子。

奇怪的是,viewpager在没有此设置的情况下工作。

答案 1 :(得分:0)

PagerTabStrip不应该是ViewPager的子代。

<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.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
            android:id="@+id/viewpager"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

</RelativeLayout>