使用PagerSlidingTabStrip时出现InflateException

时间:2015-05-14 13:38:52

标签: android android-viewpager android-tabs

我尝试使用以下库来滑动标签: https://github.com/astuetz/PagerSlidingTabStrip

我已经安装了解决方案,解压缩,在我的Eclipse中导入了库,构建了库项目,获取了library.jar文件并将其作为库添加到我的项目中。

图书馆项目结构如下:

库 - > src - > com.astuetz - > PagerSlidingTabStrip.java

然后我将该代码添加到我的片段XML文件中:



<com.astuetz.PagerSlidingTabStrip
	        android:id="@+id/tabs"
	        android:layout_width="match_parent"
	        android:layout_height="48dip"
	        android:background="@drawable/ic_calendar" />
        
        <ViewPager
            android:id="@+id/viewPager"
		    android:layout_width="match_parent"
		    android:layout_height="match_parent"
		    android:layout_below="@+id/tabs">

        
        </ViewPager>
&#13;
&#13;
&#13;

当我试图运行时,我收到以下错误:

&#13;
&#13;
05-14 15:11:36.938: E/AndroidRuntime(1368): FATAL EXCEPTION: main
05-14 15:11:36.938: E/AndroidRuntime(1368): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.horizons.engiz/com.horizons.engiz.ui.MainActivity}: android.view.InflateException: Binary XML file line #150: Error inflating class com.astuetz.PagerSlidingTabStrip
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.os.Looper.loop(Looper.java:137)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.ActivityThread.main(ActivityThread.java:4745)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at java.lang.reflect.Method.invokeNative(Native Method)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at java.lang.reflect.Method.invoke(Method.java:511)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at dalvik.system.NativeStart.main(Native Method)
05-14 15:11:36.938: E/AndroidRuntime(1368): Caused by: android.view.InflateException: Binary XML file line #150: Error inflating class com.astuetz.PagerSlidingTabStrip
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at com.horizons.engiz.ui.FragTasksList.onCreateView(FragTasksList.java:59)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.BackStackRecord.run(BackStackRecord.java:635)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.Activity.performStart(Activity.java:5017)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	... 11 more
05-14 15:11:36.938: E/AndroidRuntime(1368): Caused by: java.lang.reflect.InvocationTargetException
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at java.lang.reflect.Constructor.constructNative(Native Method)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	... 23 more
05-14 15:11:36.938: E/AndroidRuntime(1368): Caused by: java.lang.NoClassDefFoundError: com.astuetz.pagerslidingtabstrip.R$drawable
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at com.astuetz.PagerSlidingTabStrip.<init>(PagerSlidingTabStrip.java:98)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	at com.astuetz.PagerSlidingTabStrip.<init>(PagerSlidingTabStrip.java:107)
05-14 15:11:36.938: E/AndroidRuntime(1368): 	... 26 more
&#13;
&#13;
&#13;

任何帮助?

1 个答案:

答案 0 :(得分:2)

您可以发布完整的错误吗?我总是在PagerSlidingTabStrip中使用ViewPager,你有没有试过它?

<强>更新

试试这样:

<LinearLayout
    android:orientation="vertical"
    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=".MainActivity">

    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="48dip" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tabs">
</android.support.v4.view.ViewPager>

适合我,但我使用的是Android支持v7和#34; Android Studio IDE&#34;。