报错信息:
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: FATAL EXCEPTION: main
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: Process: tech.androidstudio.pagetabstripdemo, PID: 15801
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{tech.androidstudio.pagetabstripdemo/tech.androidstudio.pagetabstripdemo.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class PagerTabStrip
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:148)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5310)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class PagerTabStrip
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at tech.androidstudio.pagetabstripdemo.MainActivity.onCreate(MainActivity.java:21)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5953)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:148)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5310)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime:
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.PagerTabStrip" on path: DexPathList[[zip file "/data/app/tech.androidstudio.pagetabstripdemo-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:571)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:665)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:65)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at tech.androidstudio.pagetabstripdemo.MainActivity.onCreate(MainActivity.java:21)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5953)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:148)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5310)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime:
Suppressed: java.lang.ClassNotFoundException: android.view.PagerTabStrip
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.Class.classForName(Native Method)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime:
... 27 more
03-14 20:24:09.675 15801-15801/tech.androidstudio.pagetabstripdemo E/AndroidRuntime: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
原因:
在布局里面直接写了PagerTabStrip,应该在布局里面写下面的全路劲:android.support.v4.view.PagerTabStrip
<?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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<android.support.v4.view.ViewPager android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/viewpage">
<PagerTabStrip android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PagerTabStrip"></PagerTabStrip>
</android.support.v4.view.ViewPager>
</RelativeLayout>
解决方法”:
应该在布局里面写下面的全路劲:android.support.v4.view.PagerTabStrip
<?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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<android.support.v4.view.ViewPager android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/viewpage">
<android.support.v4.view.PagerTabStrip android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PagerTabStrip"></android.support.v4.view.PagerTabStrip>
</android.support.v4.view.ViewPager>
</RelativeLayout>