PagerSlidingTabStrip icon indicating copy to clipboard operation
PagerSlidingTabStrip copied to clipboard

Error inflating class com.astuetz.PagerSlidingTabStrip in Android Studio 3

Open alensiljak opened this issue 6 years ago • 11 comments

Just like in the issue at SO, I'm having the exception in the app during runtime after the app has been compiled with the latest Android Studio 3, Support Library, Gradle, etc.

Stack trace is here:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.money.manager.ex.debug, PID: 4699
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.money.manager.ex.debug/com.money.manager.ex.about.AboutActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.astuetz.PagerSlidingTabStrip
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                   Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.astuetz.PagerSlidingTabStrip
                   Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.astuetz.PagerSlidingTabStrip
                   Caused by: java.lang.reflect.InvocationTargetException
                      at java.lang.reflect.Constructor.newInstance0(Native Method)
                      at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                      at com.money.manager.ex.common.MmxBaseFragmentActivity.setContentView(MmxBaseFragmentActivity.java:74)
                      at com.money.manager.ex.about.AboutActivity.onCreate(AboutActivity.java:41)
                      at android.app.Activity.performCreate(Activity.java:6679)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                   Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 5 to dimension: type=0x12
                      at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:720)
                      at com.astuetz.PagerSlidingTabStrip.<init>(PagerSlidingTabStrip.java:148)
                      at com.astuetz.PagerSlidingTabStrip.<init>(PagerSlidingTabStrip.java:106)
                      at java.lang.reflect.Constructor.newInstance0(Native Method) 
                      at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
                      at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                      at com.money.manager.ex.common.MmxBaseFragmentActivity.setContentView(MmxBaseFragmentActivity.java:74) 
                      at com.money.manager.ex.about.AboutActivity.onCreate(AboutActivity.java:41) 
                      at android.app.Activity.performCreate(Activity.java:6679) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:154) 
                      at android.app.ActivityThread.main(ActivityThread.java:6119) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

alensiljak avatar Nov 02 '17 11:11 alensiljak

I have obviously missed what's updated in the whole stack. The messages of type "Can't convert value at index 5 to dimension" are also ruining FontIcon library and possibly a few others.

alensiljak avatar Nov 02 '17 11:11 alensiljak

I'm having this issue in productive app since compiling with Gradle 4 / Android Studio 3.0, but only on Pixel devices with Android 7.1 and 8.0.

hgoebl avatar Nov 04 '17 18:11 hgoebl

The good news is (and I wasn't really aware of this) that this functionality can now easily be replaced by TabLayout from the Support Library. This is what I did for MMEX. More details can be seen in the related commits in the issue linked above (1153).

alensiljak avatar Nov 04 '17 20:11 alensiljak

I'm as well having this issue, after updating from Android Studio 2.3 to 3.0.

android.view.InflateException: Binary XML file line #0: Error inflating class com.astuetz.PagerSlidingTabStrip at android.view.LayoutInflater.createView(LayoutInflater.java:640) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750) at android.view.LayoutInflater.rInflate(LayoutInflater.java:813) at android.view.LayoutInflater.rInflate(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:511) at android.view.LayoutInflater.inflate(LayoutInflater.java:415) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:614) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)  at android.view.LayoutInflater.inflate(LayoutInflater.java:511)  at android.view.LayoutInflater.inflate(LayoutInflater.java:415)  at com.zeemee.zeemee_android.discovery.fragments.SearchFragment.onCreateView(SearchFragment.java:134)  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)  at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)  at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)  at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)  at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)  at android.os.Handler.handleCallback(Handler.java:739)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:145)  at android.app.ActivityThread.main(ActivityThread.java:5832)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)  Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12 at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:573) at com.astuetz.PagerSlidingTabStrip.(PagerSlidingTabStrip.java:148) at com.astuetz.PagerSlidingTabStrip.(PagerSlidingTabStrip.java:106) at java.lang.reflect.Constructor.newInstance(Native Method)  at java.lang.reflect.Constructor.newInstance(Constructor.java:288)  at android.view.LayoutInflater.createView(LayoutInflater.java:614)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)  at android.view.LayoutInflater.inflate(LayoutInflater.java:511)  at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 

BabuinGH avatar Nov 06 '17 21:11 BabuinGH

As this user on Stackoverflow said regarding this issue.

You need to copy the java class from the library into your project and copy the resources in res folder as well. Then open the class and comment dividerPadding variable and all the associated method with it. in the method drawLine just replace its value with 0.

I did that and it worked now.

AlaaZarifa avatar Nov 13 '17 09:11 AlaaZarifa

Because I need a high level of customisation in my projects and this awesome lib seems abandoned, I created a new project that is available here. I'm working on it and I hope this week will be ready for production use. It is written with Android Studio 3. You can check it out here:

https://github.com/Crysis21/PagerTabIndicator

Crysis21 avatar Nov 13 '17 14:11 Crysis21

+1

hexi avatar Nov 23 '17 06:11 hexi

Used the solution provided by user " SWoo" (pointed out by 'AlaaZarifa' in the comment section above) on stack overflow https://stackoverflow.com/questions/47006086/error-inflating-class-com-astuetz-pagerslidingtabstrip Copy the class file from the library into your project & also paste the contents of res into the respective folders. After this be sure to call the class that you placed into your project ,instead of the dependency that was used earlier.

subind avatar Nov 24 '17 06:11 subind

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);

  1. find the layout and save it in variable

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

  1. 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);

  1. 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);

  1. add sliding tabs and viewpager in same order to linearlayout
    mainLayout.addView(mTabStripLayout);
    mainLayout.addView(mViewPager);

  2. 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);

hope it works with you like mentioned as did with me.

asha73 avatar Dec 13 '17 22:12 asha73

Thanks, it works !

gabriel-TheCode avatar Oct 03 '18 14:10 gabriel-TheCode

Thanks, it works !

ngocnd0242 avatar Aug 22 '19 14:08 ngocnd0242