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.
Related
After upgrading from Gradle wrapper 4.4.1 to 6.1.1, along with going from Android build tools 2.3.0 to 4.0.0, builds all of a sudden fail with the following error:
res/values/treeview_styles.xml:3:5-6:13: AAPT: error: invalid resource type 'attr' for parent of style.
The resource file in question looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style parent="#android:attr/listViewStyle" name="treeViewListStyle">
<item name="android:background">#android:color/white</item>
<item name="android:divider">#drawable/divider</item>
</style>
</resources>
What is happening here, and how can I fix this?
Background information: The code comes from a tree list view control I am using in my app. I have simply copied the source tree into mine so that I could make some modifications.
The developer reference for android.R.attr mentions listViewStyle, stating it has been available since API 1, so I am wondering if it is a reference to that. On the other hand, my app uses appcompat-v7, and in my local SDK tree at extras/android/support/v7/appcompat/res/values/themes_base.xml I indeed found:
<style name="Base.Theme.AppCompat.CompactMenu" parent="">
<item name="android:itemTextAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:listViewStyle">#style/Widget.AppCompat.ListView.Menu</item>
<item name="android:windowAnimationStyle">#style/Animation.AppCompat.DropDownUp</item>
</style>
That looks as if android:listViewStyle is just an alias for #style/Widget.AppCompat.ListView.Menu. Indeed, using #style/Widget.AppCompat.ListView.Menu compiles and the UI looks OK at first glance.
Note that the toolchain upgrade included switching from AAPT to AAPT2. According to this question and its answers, AAPT2 is stricter about some things than its predecessor. In particular, parents of styles must be styles as well. That would at least explain the error message, we just need to hunt down the correct resource name.
ianhanniballake wrote:
The problem is parent="#android:attr/listViewStyle", so replacing that with an actual parent theme, and not something from an attribute, would indeed fix it. What theme are you using?
In addition i found that:
Behavior changes when using AAPT2:
Additionally, when declaring a element, its parent must also
be a style resource type. Otherwise, you get an error similar to the
following:
Error: (...) invalid resource type 'attr' for parent of style
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
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>
This code
<style name="listViewPrefs" parent="#android:Widget.ListView">
...
</style>
produces the following Android Rescources Validation error:
Invalid parent reference: expected #style. There should be no cycles in
resource definitions as this can lead to runtime exceptions.
How can this be fixed?
I think you have to use like,
<style name="listViewPrefs" parent="#android:style/Widget.ListView">
...
</style>
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).