Toast.makeText Giving "Error inflating class Textview" Exception - android

Every single Toast.makeText in my app is giving me a stack trace similar to this:
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.application, PID: 8843
android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class TextView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.widget.Toast.makeText(Toast.java:263)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:240)
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:236)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.widget.Toast.makeText(Toast.java:263) 
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:240) 
at com.myapp.application.activities.ReportActivity$5.success(ReportActivity.java:236) 
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=16; index=1191
at android.content.res.StringBlock.get(StringBlock.java:65)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1151)
at android.content.res.TypedArray.getString(TypedArray.java:195)
at android.support.v7.widget.TintTypedArray.getString(TintTypedArray.java:142)
at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:243)
at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:165)
at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:80)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:70)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1016)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1073)
These are some sample Toast.makeText calls that are causing it
Toast.makeText(ReportActivity.this, "Reported for " + reportType, Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.network_unavailable, Toast.LENGTH_SHORT).show();
It all started when we upgraded our Gradle libraries and started using these versions
compileSdkVersion 27
buildToolsVersion '27.0.1'

The bug apparently occurs when using support library 26+, on API 25 and lower, and is supposedly fixed in Oreo.
See: https://issuetracker.google.com/issues/64053344
The fix in my case was to change the fontFamily defined in my default theme, by extracting sans-serif-light to a string resource, that is going from this:
<style name="AppCompatTheme" parent="android:...">
<item name="fontFamily">sans-serif-light</item>
</style>
To this:
<style name="AppCompatTheme" parent="android:...">
<item name="fontFamily">#string/default_font</item>
</style>
with in my strings.xml:
<string name="default_font" translatable="false">sans-serif-light</string>

My Toast callings was with getBaseContext(). I just change it to getApplicationContext() to solve the problem.

I solved the crashing from the Toast.makeText entries all throughout the app by doing a global search for fontFamily and deleting the entries.
It seems like the font family was being defined and the new build tools and SDK didn't like that.

Related

Can't use color statelist in navigationVIew Android kotlin

I have two project one uses color statelist selector in NavigationView to change the background color of items in Navigation Drawer on different state of interactions.
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemBackground="#color/nav_bgstate_list" <------
app:itemIconTint="#color/nav_state_list" <------
app:itemTextColor="#color/nav_state_list" <------
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
These three lines causes error but when I remove them, it works fine.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Item checked -->
<item android:color="#color/brand" android:state_checked="true" />
<!-- Item pressed -->
<item android:color="#color/black" android:state_pressed="true" />
<!-- Item default -->
<item android:color="#color/brand70" />
</selector>
I copied the same code into another project and it started throwing bunch of errors. The log is below
2021-06-09 07:49:13.564 12895-12895/ca.company.project.betaversion E/AndroidRuntime: FATAL EXCEPTION: main
Process: ca.company.project.betaversion, PID: 12895
java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.company.project.betaversion/ca.company.project.betaversion.MainActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:57)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:51)
at ca.company.project.betaversion.MainActivity.onCreate(MainActivity.kt:111)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.content.res.Resources$NotFoundException: Drawable ca.company.project.betaversion:color/nav_bgstate_list with resource ID #0x7f0600d9
Caused by: android.content.res.Resources$NotFoundException: File res/color/nav_bgstate_list.xml from drawable resource ID #0x7f0600d9
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:820)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
at android.content.res.Resources.getDrawableForDensity(Resources.java:877)
at android.content.res.Resources.getDrawable(Resources.java:819)
at android.content.Context.getDrawable(Context.java:605)
at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:455)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:147)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:135)
2021-06-09 07:49:13.569 12895-12895/ca.company.project.betaversion E/AndroidRuntime: at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
at androidx.appcompat.widget.TintTypedArray.getDrawable(TintTypedArray.java:83)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:196)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:122)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:57)
at ca.company.project.betaversion.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:51)
at ca.company.project.betaversion.MainActivity.onCreate(MainActivity.kt:111)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:189)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:122)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:807)
... 36 more
I checked minSdk version, compilied sdk version, themes, gradle version, dependencies with their versions etc. and everything is same, nothing is different. I know I should be using drawable states instead of color state but I don't understand why it is working in other project but in the another one.
Edit 1
I found out that the crash was happening because of I set the itembackground with color state selector. itemIconTint and itemTextColor works fine with color state selectors. Only itemBackground crashes whenever I try to set the state selector there so I found one solution mentioned here, basically I need to add checked android:checkable="true" but even after adding this it crashed. I don't know why.
Edit 2
So I realized color state selector is working on newer version of android > 10 but not on the older version of android.

How can I solve inflating class error at Kotlin?

I'm trying to add payment from for my application. I use that library for that. I added it to my project. I'm also try delete from gradle and re-install it but it gave same error again.
Here my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OdemeSayfasi">
<com.fevziomurtekin.payview.Payview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/payview"/>
</LinearLayout>
In run time I got error which is:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.slidework3, PID: 23708
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.slidework3/com.example.slidework3.OdemeSayfasi}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.fevziomurtekin.payview.Payview
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.fevziomurtekin.payview.Payview
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.slidework3.OdemeSayfasi.onCreate(OdemeSayfasi.kt:22)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
This error is very long so I get only first parts of it.
How can I solve it? I try to inflate layout but I can't solve it. I'm waiting for your advices and help.
I tried to replicate it and noticed this message alongside with what you have shown:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
The reason being the library uses MDC.
I had to change the existing app theme applied into Material Design Component(MDC) based, so to make avoid the error; Example: In under style.xml:
<style name="AppTheme"parent="Theme.MaterialComponents.Light.NoActionBar">
Edit: If you don't want to affect the apptheme, you can just apply a Material Component theme to just the payview.
<com.fevziomurtekin.payview.Payview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/payview"
android:theme="#style/Theme.MaterialComponents"/>
If you want to customise your payview, just create a custom theme whose parent based on Theme.MaterialComponents .

BottomNavigationView inflating error. Resources$NotFoundException: Resource ID #0x0

I'm having some problem with BottomNavigationView from design support library.
I am using it in my activity_main.xml:
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
app:itemIconSize="16dp"
app:labelVisibilityMode="labeled"
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
app:itemBackground="#color/medium_purple"
app:menu="#menu/main"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The app crashes when inflating that xml. The full stack trace of the exception is below:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.frolo.musp.dev/com.alexfrolov.mp.main.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:651)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.alexfrolov.mp.main.MainActivity.onCreate(MainActivity.java:165)
at android.app.Activity.performCreate(Activity.java:7074)
at android.app.Activity.performCreate(Activity.java:7065)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:220)
at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:93)
at android.content.res.Resources.getColorStateList(Resources.java:1034)
at android.content.Context.getColorStateList(Context.java:631)
at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:67)
at android.support.design.internal.BottomNavigationMenuView.createDefaultColorStateList(BottomNavigationMenuView.java:467)
at android.support.design.internal.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:101)
at android.support.design.internal.BottomNavigationMenuView.<init>(BottomNavigationMenuView.java:86)
The versions of all support libs and the version of compileSdk are same. I really don't understand what a hell is that. Can anybody explain me please?
Thanks
I had this problem and it baffled me for a day or so. Basically, the BottomNav wants a colorstatelist defined for textColorSecondary in your theme as opposed to a just plain color. So I went from:
<style name="MTheme" parent="Theme.MaterialComponents.Light.Bridge">
...
<item name="android:textColorSecondary">#295055</item>
to
<style name="MTheme" parent="Theme.MaterialComponents.Light.Bridge">
...
<item name="android:textColorSecondary">#color/secondary_textcolor</item>
where secondary_textcolor equals
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:color="#295055"/>
<item android:state_enabled="false" android:color="#color/disabled"/>
</selector>
I wasted a lot of time adding and removing dependencies trying to find this solution.
The problem is in your question title
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
It means that you are using a resource that is not existent. I cannot know which it is but this is how you will fix. Go to the file #menu/main and remove all attributes for icons. You can leave the text. Add one by one to check which one is the problem. It is most likely to be that your icons have been mistakenly placed inside the folder drawable-24 instead of drawable or a higher android API folder than the one you are testing on. Sometimes we make those mistakes.
Also note that some attributes only apply starting a certain android API. Consider checking the attributes starting with app.
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
app:itemBackground="#color/medium_purple"

Creating an Activity caused Error inflating class android.support.design.widget.CoordinatorLayout

The app was just working fine and then I added a new Activity and it started giving me this error. I have tried setting the theme to app compat theme and also using app compat activity. Still nothing working.
Process: info.androidhive.loginandregistration, PID: 28764
java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.loginandregistration/info.androidhive.loginandregistration.activity.MainScreenActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
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.parseInclude(LayoutInflater.java:964)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at info.androidhive.loginandregistration.activity.MainScreenActivity.onCreate(MainScreenActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:185)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:179)
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.parseInclude(LayoutInflater.java:964) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854) 
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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at info.androidhive.loginandregistration.activity.MainScreenActivity.onCreate(MainScreenActivity.java:69) 
at android.app.Activity.performCreate(Activity.java:6664) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library
My guess is that:
When you first created the app, and you created the first activity in the new-project wizard, you unchecked the "Make Backwards Compatible (AppCompat)" checkbox
When you added your new activity, you did so via the new-activity wizard, and this time you left that checkbox checked
Your overall application theme will not use Theme.AppCompat, because you opted out of appcompat-v7 by unchecking that checkbox. Your new activity is extending AppCompatActivity, but it is still using the application theme, and that is a conflict that would generate the error.
Tactically, change your new MainScreenActivity to have it extend from Activity, not AppCompatActivity. You may need to make some other adjustments depending on what activity template you chose and what resources it created (e.g., change app: to android: on attributes in menu resources).
Strategically, you need to decide whether you want to use appcompat-v7 or not, then stick with that choice for this project. Using appcompat-v7 gives you a somewhat consistent look-and-feel across Android versions (back to API Level 14), at the cost of your app being ~1MB bigger and some additional complexity when writing the app.

Binary XML file line #: Error inflating error for Spinner : Only on Android (6.0)-Marshmallow

ArrayAdapter < String > dataAdapter = new ArrayAdapter < String >
(this, R.layout.spinner_list_item, list0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
dataAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
} else {
dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_custom);
}
mSpinner0.setAdapter(dataAdapter);
I also tried above code but no results..
I am using custom xml adpter.setDropDownViewResource() method like dataAdapter.setDropDownViewResource
(R.layout.simple_spinner_dropdown_custom);
There is total 3 spinner in my Layout.
It's working fine with other 2 Spinner But fist spinner click gives me this error in Android 6.0.
It's working fine in Android L (API-22)
Please help.
Thanks in advance.
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:textColor="#color/normal_color"
android:ellipsize="marquee"
android:padding="10dp"
android:background="#color/white"
android:layout_height="wrap_content" />
log
E/GAv4: Successfully bound to service but never got onServiceConnected
callback E/AndroidRuntime: FATAL EXCEPTION: main Process: com.abc.xyz, PID: 22725
android.view.InflateException: Binary XML file line #19: Binary XML file
line #19: Error inflating class <unknown> at
android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
atandroid.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448)
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963)
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959)
at android.widget.Spinner.measureContentWidth(Spinner.java:833)
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220)
at android.widget.Spinner.performClick(Spinner.java:758)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
atcom.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)at
android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448) 
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963)  at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959)  at android.widget.Spinner.measureContentWidth(Spinner.java:833)  at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194)  at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220)  at android.widget.Spinner.performClick(Spinner.java:758)  at android.view.View$PerformClick.run(View.java:21163)  at android.os.Handler.handleCallback(Handler.java:746)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5443)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)  Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at android.view.LayoutInflater.createView(LayoutInflater.java:619)at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378) 
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448) 
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963) 
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959) 
at android.widget.Spinner.measureContentWidth(Spinner.java:833) 
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194) 
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220) 
at android.widget.Spinner.performClick(Spinner.java:758) 
at android.view.View$PerformClick.run(View.java:21163) 
at android.os.Handler.handleCallback(Handler.java:746) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:482)
at android.widget.TextView.<init>(TextView.java:750)
at android.widget.TextView.<init>(TextView.java:671)
at android.widget.TextView.<init>(TextView.java:667)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378) 
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448) 
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963) 
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959) 
at android.widget.Spinner.measureContentWidth(Spinner.java:833) 
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194) 
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220) 
at android.widget.Spinner.performClick(Spinner.java:758) 
at android.view.View$PerformClick.run(View.java:21163) 
at android.os.Handler.handleCallback(Handler.java:746) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
I had the same issue. It happens if you add a theme to your drop down item. You should apply a theme only to your spinner. In your case, you have added a style to the TextView. You have not posted what that style contains, but if it has a theme such as
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
you need to remove it.

Categories

Resources