6

After I update my Android studio from 2.3.3 to 3.0 and I got this error after compiled and run (rror inflating class com.astuetz.PagerSlidingTabStrip) Please see the Log Error below:

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) 
Iman Marashi
  • 5,593
  • 38
  • 51
ralph danding
  • 69
  • 1
  • 4
  • 3
    This library has one java file and three xml files. I first thought this issue is because it is using a really old version of gradle and SDK both different from my project but I didn't want to fork a one file library so I just copied the source file and xml files into the library that uses this one file library in my project and changed the relative package/import - it still crashed on the same line. So I commented out the one line that is crashing and let it use the default value for dividerPadding and that worked. This a horrible hack but it works if you have to use the same class. – SWoo Nov 01 '17 at 04:56
  • Do you have any idea or steps to fix this error please? – ralph danding Nov 07 '17 at 21:53
  • 1
    1.)git clone https://github.com/astuetz/PagerSlidingTabStrip.git
    2.)copy the java file into your local chat_ui directory. copy the contents of the xml files in that project into the chat_ui appropriate directories. One of them is the same name as an existing one, IIRC the contents are the same, too, but important thing is the definitions have to exist in chat_ui.
    3.) change the package of the copied java file from stuetz to chat_ui. 4.) change the resource reference in the copied java file from stuetz to chat_ui. 5. Comment out the line that is crashing. //dividerPadding =
    – SWoo Nov 08 '17 at 04:22

3 Answers3

4

Try to change your .xml with this info:

<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"/>

In my case the problem was with Android devices 7.0, and i was using

    <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"/>

I think the problem ws pstsShouldExpand, or that is necesary the margin top.

Regards.

Max Pinto
  • 1,463
  • 3
  • 16
  • 29
  • 6
    I have tested it out and the result is: 1. pstsShouldExpand="true" causes inflater to crash. 2. you can still call tabStrip.setShouldExpand(true); in code before call of setViewPager and it will work. – EdgarK Sep 25 '18 at 12:09
1

you can leave dependency reference in gradle but do not inflate using inflater (seems to me the problem exists in inflating the slider tabs from XLM file) rather create the tabsliding object using code inside your activity onCreate, the problem starts when you inflate from XLM.

This is what I successfully did:

1) set your activity contentview to empty linearlayout XLM file

   setContentView(R.layout.pagerslidingtabstrip_viewpager);

2) find the layout and save it in variable

   LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout_view);

3) inflate your viewpager from separate XLM file than contains only the viewpager element

    mLayoutInflater = getLayoutInflater();
    mInflatedViewPagerLayout =  mLayoutInflater.inflate(R.layout.separate_viewpager,null);
    mViewPager = mInflatedViewPagerLayout.findViewById(R.id.viewpager);

4) create and configure your sliding tabs from code

    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) add sliding tabs and viewpager in same order to linearlayout

    mainLayout.addView(mTabStripLayout);
    mainLayout.addView(mViewPager);

5) complete remaining setup as usual like creating adapter, assigning adapter to viewpager, and assigning viewpager to sliding tabs

    mPagerAdapter = new SampleFragmentPagerAdapter2(getSupportFragmentManager());
    mViewPager.setAdapter(mPagerAdapter);
    mTabStripLayout.setViewPager(mViewPager);
ams73
  • 146
  • 5
0

I replaced Pageslidingtabstrip to android studio custom tab and it works fine..

ralph danding
  • 69
  • 1
  • 4