我将Android工作室从2.3.3更新到3.0后,编译运行后出现此错误(rror inflating class com.astuetz.PagerSlidingTabStrip)请参阅下面的日志错误:
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.astuetz.PagerSlidingTabStrip
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2643)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2709)
at android.app.ActivityThread.access$1000(ActivityThread.java:196)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1026)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:887)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.astuetz.PagerSlidingTabStrip
at android.view.LayoutInflater.inflate(LayoutInflater.java:545)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:436)
at android.app.Activity.setContentView(Activity.java:2205)
at com.goalplusapp.goalplus.MainActivity.onCreate(MainActivity.java:325)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2709)
at android.app.ActivityThread.access$1000(ActivityThread.java:196)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1026)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:887)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.astuetz.PagerSlidingTabStrip
at android.view.LayoutInflater.createView(LayoutInflater.java:654)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:809)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:880)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.inflate(LayoutInflater.java:521)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:436)
at android.app.Activity.setContentView(Activity.java:2205)
at com.goalplusapp.goalplus.MainActivity.onCreate(MainActivity.java:325)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2709)
at android.app.ActivityThread.access$1000(ActivityThread.java:196)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1026)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:887)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:628)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:809)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:880)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.inflate(LayoutInflater.java:521)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:436)
at android.app.Activity.setContentView(Activity.java:2205)
at com.goalplusapp.goalplus.MainActivity.onCreate(MainActivity.java:325)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2709)
at android.app.ActivityThread.access$1000(ActivityThread.java:196)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1026)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:887)
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x5
at android.content.res.TypedArray.getColor(TypedArray.java:451)
at com.astuetz.PagerSlidingTabStrip.<init>(PagerSlidingTabStrip.java:144)
at com.astuetz.PagerSlidingTabStrip.<init>(PagerSlidingTabStrip.java:106)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:628)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:809)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:880)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.inflate(LayoutInflater.java:521)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:436)
at android.app.Activity.setContentView(Activity.java:2205)
at com.goalplusapp.goalplus.MainActivity.onCreate(MainActivity.java:325)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2709)
at android.app.ActivityThread.access$1000(ActivityThread.java:196)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1026)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:887)
答案 0 :(得分:3)
尝试使用以下信息更改.xml:
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs_quotation_track"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@drawable/background_tabs"
android:layout_marginTop="20dp"/>
在我的情况下问题出在Android设备7.0上,我正在使用
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs_quotation_track"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@drawable/background_tabs"
app:pstsShouldExpand="true"/>
我认为这个问题是pstsShouldExpand,或者这是必要的优势。
问候。
答案 1 :(得分:0)
你可以在gradle中保留依赖引用,但不要使用inflater进行膨胀(在我看来,从XLM文件中膨胀滑块选项卡时存在问题)而是使用活动onCreate中的代码创建tabliding对象,问题在你膨胀时开始来自XLM。
这就是我成功做到的:
1)将您的活动内容视图设置为清空linearlayout XLM文件
setContentView(R.layout.pagerslidingtabstrip_viewpager);
2)找到布局并将其保存在变量
中 LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout_view);
3)从单独的XLM文件中扩展viewpager,而不是仅包含viewpager元素
mLayoutInflater = getLayoutInflater();
mInflatedViewPagerLayout = mLayoutInflater.inflate(R.layout.separate_viewpager,null);
mViewPager = mInflatedViewPagerLayout.findViewById(R.id.viewpager);
4)从代码
创建和配置滑动标签 mTabStripLayout = new PagerSlidingTabStrip(this);
mTabStripLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 140));
mTabStripLayout.setShouldExpand(true);
mTabStripLayout.setAllCaps(true);
mTabStripLayout.setTextSize(60);
mTabStripLayout.setTextColor(Color.BLACK);
mTabStripLayout.setDividerColor(Color.BLUE);
mTabStripLayout.setDividerPadding(30);
mTabStripLayout.setIndicatorColor(Color.RED);
mTabStripLayout.setIndicatorHeight(15);
mTabStripLayout.setUnderlineColor(Color.BLUE);
4)以相同的顺序添加滑动标签和viewpager到linearlayout
mainLayout.addView(mTabStripLayout);
mainLayout.addView(mViewPager);
5)照常完成剩余设置,例如创建适配器,将适配器分配给viewpager,以及将viewpager分配给滑动标签
mPagerAdapter = new SampleFragmentPagerAdapter2(getSupportFragmentManager());
mViewPager.setAdapter(mPagerAdapter);
mTabStripLayout.setViewPager(mViewPager);
答案 2 :(得分:0)
我将Pageslidingtabstrip替换为android studio自定义选项卡,它工作正常..