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>
Related
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
Whenever i run the code as an application in my Eclipse it shows an error:
\workspace\appcompat_v7\res\values-v21\themes_base.xml:150: error: Error: No resource found that matches the given name: attr 'android:windowElevation'.
But the example files runs. How to rectify it?
Make sure your appcompat_v7 targeting Android 5.0 or later.
First check your minApi:
Notice that android:windowElevation works for API > 20
If your API is right:
make sure you have installed Android 5.0 SDK via the SDK-Manager
For pre-lollipop devices check this
change this line in your style.xml file
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
to :
<style name="AppBaseTheme" parent="android:Theme.Light">
This is the manifest :
<application
android:allowBackup="true"
android:icon="#drawable/professor"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
This is the Style :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#DC980005</item>
</style>
When I change the background color the application is crushed and closed!
I searched alot in the internet but no reason for the application to not open!
Please any help..
This is the logCat :
01-24 16:52:47.951 28973-28973/com.example.user.ascs E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.user.ascs, PID: 28973
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.ascs/com.example.user.ascs.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Why the android studio is forcing me to use this?
Android Studio is not "forcing" you to do anything.
My guess is that you created a new project in Android Studio, and in there you created a new activity. The templates for such a project set up the project to use appcompat-v7 and its ActionBarActivity, Theme.AppCompat, etc. This gives you an action bar that works back to API Level 7, whereas the native action bar only works back to API Level 11. And the appcompat-v7 action bar resembles the Material Design action bar that is native to Android 5.0.
You do not have to use any of that. It is merely what was given to you from a template. If you do not like what is in the template, you need to change the files that were generated for you from the template. This is no different than how templates work in any other tool, whether a development tool (e.g., Web site generator) or an office productivity tool (e.g., Microsoft Word).
In this specific case, you are welcome to:
Remove the appcompat-v7 line from your dependencies in your build.gradle file. In a typical Android Studio project, that file would be the one in your app/ module directory.
Change your activity to inherit from Activity instead of ActionBarActivity.
Change your theme to not use Theme.AppCompat.
Change your menu resources (app/src/main/res/menu/* in a typical Android Studio project) to replace any app: prefixes with android: ones (e.g., app:showAsAction becomes android:showAsAction).
Then, you will not be using appcompat-v7 anymore. You will be using the native action bar on API Level 11+, falling back to the old-style options menu if your minSdkVersion is lower than 11. You will be able to have your theme inherit from one of the Theme.Holo series, optionally inheriting from Theme.Material for Android 5.0+ devices (e.g., in a res/values-v21/styles.xml file).
I am using actionbar sherlock for compatibility with android version >= 8
and while using the code it gives me error
error: Error: No resource found that matches the given name: attr 'titleTextStyle'.
my code used in the xml is
<style name="MyTheme.ActionBarStyle" parent="#style/Widget.Sherlock.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
You have to change the build SDK to at least API 11 (Honeycomb).
I have experiment this issue too with AndroidSherlock ActionBar. EveryTime I change something inside style I get those erros to. Closing the the style file and clean -> rebuild fix tipically for me
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.