AppCompatSpinner throwing InflateException on only few devices - android

Two days i was stuck with IllegalArgument Exception(given the crash log below) while clicking on the custom AppCompatSpinner.
This issue is not happening in all devices, only few devices(Samsung, Oneplus) affected.
App themes are listed below for all the api version
parent="Theme.AppCompat.NoActionBar"
v23 theme:
parent="Theme.AppCompat.Light.NoActionBar"
v21 theme :
parent="Theme.MaterialComponents.DayNight.NoActionBar"
My crash log:
E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #95: Binary XML file line #37: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class Button
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
Please give some insights to fix this issue. Found some solutions in stackoverflow & other sites but nothing helped me to fix the issue

If you want to use Material UI elements, then
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> should be changed to <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">.
As the error itself is saying, your app theme must be a child of MaterialTheme or any child of the same.
How to build a material theme

Related

WebView throws InflateException on android 5.0 [duplicate]

This question already has answers here:
android.view.InflateException Error inflating class android.webkit.WebView
(21 answers)
Closed 3 years ago.
After upgrading to "androidx.appcompat:appcompat:1.0.2" and "com.google.android.material:material:1.1.0-beta01" the WebView crashes on devices with Android 5.0 and throws this exeption android.view.InflateException
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.WebView
How can I fix it?
As explained here, this issue is due to the this revision. It affects Lollipop devices with webview version<50. Use the following code as a solution.
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
if (Build.VERSION.SDK_INT in 21..25 && (resources.configuration.uiMode == AppConstants.appContext.resources.configuration.uiMode)) {
return
}
super.applyOverrideConfiguration(overrideConfiguration)
}
What about your targetSdkVersion and your buildTools version? Once I had a very similar issue. I started seeing this exception when I raised the targetSdkVersion to 25 and the build tools to 25.0.2.
Also try to update your app theme to inherit from Theme.MaterialComponents (or a descendant). Change your AppTheme parent to Theme.MaterialComponents.
Example
Before:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
After:
<!-- Material application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

android.support.design.chip.Chip

I'm face to a problem with chip component on android.
I try to implemente a chip like this:
<android.support.design.chip.Chip
android:id="#+id/tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world"/>
But when I launch my app I have this error:
android.view.InflateException: Binary XML file line #59: Binary XML file line #59: Error inflating class
android.support.design.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #59:
Error inflating class android.support.design.chip.Chip
Caused by: java.lang.IllegalArgumentException: The style on this
component requires your app theme to be Theme.AppCompat (or a
descendant).
My style is already an AppCompact.
You need to use app theme to Theme.MaterialComponents.Light.Bridge inspite of AppCompat if you want to use android.support.design.chip.Chip.
Reason:
Chip component relies on new MaterialComponents theme, so is why the
crash occurs. Bridge theme here are treated as AppCompat but
provides new MaterialComponents theme when needed.

Android Error inflating class TextInputLayout

I'm trying to use TextInputLayout in my XML, and I'm meeting this error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.jechange.moncompte/fr.jechange.moncompte.SignUpActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;
I've imported the design library, and the support-v7-appcompat library. And I'm using the Theme.AppCompat.Light.NoActionBar theme.
The XML in which I'm using the Text Input Layout contains just something like that:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res="http://schemas.android.com/apk/res-auto"
style="#style/matchParent">
<android.support.design.widget.TextInputLayout
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
if you are calling layout(containg TextInputLayout) from activity then
nothing just use YouActivityClassName.this in place of getApplicationcontext or YourApplicationClassName.getcontext() or other where you are passing context
I had the same issue fixed here.
Make sure you don't have any other support library import v4 and v7. You can use only the design-support library. Also you should make sure your theme "matchParent" inherit from Theme.AppCompat for all the platform you trying to run.
My issue was only on Lollipop because of the values-21/style.xml.
Hope it will help.

R file for custom component not compiling

I have two custom components, one which I made quite recently, both in Android Studio. The earlier one worked. I followed the same procedure to make the new one but it throws runtime errors when I reach the activity screen during testing.
These are the exception messages, listed in order:
1. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sentient/com.mycompany.MyActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class <unknown>
2. Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class <unknown>
3. java.lang.reflect.InvocationTargetException
4. java.lang.NoClassDefFoundError: com.mycomponent.R$color
Error #4 shows the actual line itself that throws the error, it is part of the constructor of the component:
int color = res.getColor(R.color.progress_gray);
I checked the R file manually, and found the colors (progress_gray is defined in the colors.xml) to be present. I removed the line, and another line throws the error instead (which again depends on the R file to get information).
I have tried cleaning, changing build order in gradle, Make the component separately, and I still can't figure out where the mistake is. Any help is appreciated! Thanks.
can you post the xml file of the custom view?
Check if you have added to your main layout of the custom view xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
I got the solution. The applicationId in build.gradle and the package in the manifest were not matching. Once I changed it, it worked.
Strange though, I had thought that the reason the two were separated was so that they could be named differently. In any case, that was what got it working.

Android theme declaration

I have a problem. I created new app and publish it to market, but most part of users get ANR with
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 39 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010019 a=-1}
at android.content.res.Resources.loadDrawable(Resources.java:1699)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.(View.java:1998)
at android.view.View.(View.java:1946)
at android.view.ViewGroup.(ViewGroup.java:304)
at android.widget.RelativeLayout.(RelativeLayout.java:173)
... 42 more
In my app I have a two themes that declared in themes.xml. I think I have a mistake in theme declaration. How properly define themes in styles? What difference between
<style name="DarkTheme" parent="android:Theme.Black.NoTitleBar">
and
<style name="DarkTheme" parent="#android:style/Theme.NoTitleBar">
<style name="DarkTheme" parent="#android:style/Theme.NoTitleBar">
That theme declaration is correct. The #android tells your software to look inside the Android package for resources. :style means that inside the android package it should look at the styles of that package for the style named after the /.
I'm using something similar to the first way of defining the theme parent, i.e.:
<style name="DarkTheme" parent="android:Theme.Black.NoTitleBar">
It works just fine for me. Perhaps try only using that. I've tried both ways and they seemed to work though.

Categories

Resources