getView() crashes in getDrawable() - android

I get many weird reports of app crashes (using app compat library) when OS calls the getView() of one of my adapter. It crashes in getDrawable() with ResourceNotFoundException under Android 4.x or RuntimeException under Android 5.x or UnsupportedOperationException under Android 6.x. The getView() is actually calling inflate() with a mostly simple layout file.
The call stack is always like this:
at android.content.res.TypedArray.getDrawable (TypedArray.java)
at android.view.View.<init> (View.java:3756)
at android.view.ViewGroup.<init> (ViewGroup.java)
at android.widget.LinearLayout.<init> (LinearLayout.java)
at android.widget.LinearLayout.<init> (LinearLayout.java)
at android.widget.LinearLayout.<init> (LinearLayout.java)
at java.lang.reflect.Constructor.newInstance (Constructor.java)
at java.lang.reflect.Constructor.newInstance (Constructor.java)
at android.view.LayoutInflater.createView (LayoutInflater.java)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView (PhoneLayoutInflater.java)
at android.view.LayoutInflater.onCreateView (LayoutInflater.java)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java)
at android.view.LayoutInflater.inflate (LayoutInflater.java)
at android.view.LayoutInflater.inflate (LayoutInflater.java)
at android.view.LayoutInflater.inflate (LayoutInflater.java)
at my_app.activity$adapter.getView
Here is the layout files that 'cause' this on Android 4.x and 5.x:
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"/>
<TextView
android:id="#+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
<ImageButton
android:id="#+id/menu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#00000000"
android:src="#drawable/ic_menu_moreoverflow_normal_holo_dark"/>
The only drawable used in that layout is available in hdpi, mdpi and xhdpi. How come Android cannot find it? By the way, I can't reproduce this in emulator or an actual device running 4.x or 5.x!
Any suggestions will be appreciated, Those are my top 4 app crashes representing more than 90% of those!
I used to have background set to #null and changed it to #00000000 to no avail. Also included the drawable in theme's attributes and having src="?menu_overflow" but it didn't change anything.

Try
app:srcCompat="#drawable/ic_menu_moreoverflow_normal_holo_dark"
instead of
android:src="#drawable/ic_menu_moreoverflow_normal_holo_dark" // in your image button
Update
Dont forget to use android's android.support.v7.widget.AppCompatImageButton instead of ImageButton (this wont crash ).
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/menu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#00000000"
app:srcCompat="#drawable/ic_menu_moreoverflow_normal_holo_dark"/>

Related

Android Application crash on Android 13

Getting weird crash in Samsung android 13 devices, but this is working fine in other devices. Recently we are getting one crash in firebase crash analytics, below is the crash report . Application is targeting api level 33 and so far crash reported only in samsung android 13 devices.
edit_texts.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_input1_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/input_field_text_color"
android:theme="#style/login_floating_text_style">
<com.mobileaware.unified.ui.controls.common.MaEditText
android:id="#+id/login_input1"
style="#style/input_field_validation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_input2_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/input_field_text_color"
android:theme="#style/login_floating_text_style">
<com.mobileaware.unified.ui.controls.common.MaEditText
android:id="#+id/login_input2"
style="#style/input_field_validation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_input3_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/input_field_text_color"
android:theme="#style/login_floating_text_style">
<com.mobileaware.unified.ui.controls.common.MaEditText
android:id="#+id/login_input3"
style="#style/input_field_validation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
Stack Trace :
Fatal Exception: android.view.InflateException
Binary XML file line #21 `com.xyz.abc:layout/edit_texts: Attempt to invoke virtual method 'int android.graphics.Typeface.getWeight()' on a null object reference
Caused by java.lang.NullPointerException
Attempt to invoke virtual method 'int android.graphics.Typeface.getWeight()' on a null object reference
keyboard_arrow_up
com.google.android.material.resources.TypefaceUtils.maybeCopyWithFontWeightAdjustment (TypefaceUtils.java:57)
com.google.android.material.internal.CollapsingTextHelper.setCollapsedTypefaceInternal (CollapsingTextHelper.java:480)
com.google.android.material.internal.CollapsingTextHelper.setTypefaces (CollapsingTextHelper.java:463)
com.google.android.material.textfield.TextInputLayout.setEditText (TextInputLayout.java:1426)
com.google.android.material.textfield.TextInputLayout.addView (TextInputLayout.java:836)
android.view.ViewGroup.addView (ViewGroup.java:5268)
android.view.LayoutInflater.rInflate (LayoutInflater.java:1149)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:1106)
android.view.LayoutInflater.rInflate (LayoutInflater.java:1148)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:1106)
android.view.LayoutInflater.inflate (LayoutInflater.java:692)
android.view.LayoutInflater.inflate (LayoutInflater.java:544)
arrow_right
com.mobileaware.unified.ui.fragments.NativeLoginFragment.showTabs (NativeLoginFragment.java:364)
com.mobileaware.unified.ui.presenters.NativeLoginFragmentPresenter.bind (NativeLoginFragmentPresenter.java:92)
com.mobileaware.unified.ui.presenters.NativeLoginFragmentPresenter.loadData (NativeLoginFragmentPresenter.java:114)
com.mobileaware.unified.ui.presenters.BasePresenter.loadData (BasePresenter.java:484)
com.mobileaware.unified.ui.fragments.NativeLoginFragment.injectPresenter (NativeLoginFragment.java:673)
com.mobileaware.unified.ui.fragments.BaseFragment.onResume (BaseFragment.java:214)
com.mobileaware.unified.ui.fragments.NativeLoginFragment.onResume (NativeLoginFragment.java:1244)
androidx.fragment.app.Fragment.performResume (Fragment.java:3071)
androidx.fragment.app.FragmentStateManager.resume (FragmentStateManager.java:605)
androidx.fragment.app.FragmentStateManager.moveToExpectedState (FragmentStateManager.java:285)
androidx.fragment.app.SpecialEffectsController$FragmentStateManagerOperation.complete (SpecialEffectsController.java:771)
There's probably an issue in implementation of TextInputLayout, as it can call: (TextInputLayout.java:1426)
collapsingTextHelper.setTypefaces(this.editText.getTypeface());
with null typeface.
It happened when turning on the Bold text in Android 13:
Settings -> Display size & text -> Bold text
In my case the issue was in the style of com.google.android.material.textfield.TextInputEditText.
So try to remove and fix the style of MaEditText in your case.

Android : Class not allowed to be inflated android.widget.Switch

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/general_dts_title"
style="#style/TextAppearance.Compat.Notification.Line2"
android:layout_alignParentBottom="false"
android:layout_alignBottom="#+id/imgToggle"
android:textSize="16sp" />
<Switch
android:id="#+id/imgToggle"
android:layout_width="42dp"
android:layout_height="28dp"
android:layout_gravity="right"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" />
</RelativeLayout>
StatusBar: Caused by: android.view.InflateException: Binary XML file line #338 in com.dts.dtsxultra:layout/view_notification_sample: Class not allowed to be inflated android.widget.Switch ...
Could you please help.
I tried removing background attribute, but still it is not working.
I have tried the above piece of code, without giving the style to the textview, it works great. The error that you are facing may not be because of the piece of code.
RemoveView only allows some layout and widget to inflate. android.widget.Switch as in the error you are getting is not supported by RemoteView. You can see the list of supported views here

How to make ConstraintLayout (androidx.constraintlayout.widget) work with MaterialButton (com.google.android.material.button)?

Problem statement
I am using com.google.android.material.button.MaterialButton inside androidx.constraintlayout.widget.ConstraintLayout where the constraint layout cannot deploy or detect the constraints of the material button.
Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".views.screens.VeritasFolderReadSelectionScreen">
<androidx.appcompat.widget.Toolbar
android:id="#+id/folderSelectToolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/startGrad"
android:minHeight="?attr/actionBarSize"
android:theme="#style/AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/folderSelectMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:text="Select folders you want PeerPots to read"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/folderSelectToolbar"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/folderRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:layout_constraintTop_toBottomOf="#id/folderSelectMessage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<!-- Following code not working -->
<com.google.android.material.button.MaterialButton
android:id="#+id/folderViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:textSize="12sp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
ScreenShot
Material button not visible
UPDATED
The error thrown while rendering
java.lang.IllegalArgumentException:
java.lang.ClassCastException#207d8929 at
sun.reflect.GeneratedMethodAccessor226.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108)
at
android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)
at
android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)
at
android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
at
android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
at
android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
at
android.animation.ValueAnimator.animateBasedOnTime(ValueAnimator.java:1339)
at
android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1471)
at
android.animation.ValueAnimator.pulseAnimationFrame(ValueAnimator.java:1490)
at android.animation.AnimatorSet.pulseFrame(AnimatorSet.java:1163)
at
android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1146)
at
android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:1046)
at
android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
at
android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
at
android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:947)
at android.view.Choreographer.doCallbacks(Choreographer.java:761) at
android.view.Choreographer_Delegate.doFrame(Choreographer_Delegate.java:66)
at
com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:563)
at
com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:425)
at
com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:120)
at
com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:151)
at
com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:133)
at
com.android.tools.idea.rendering.RenderTask.lambda$null$8(RenderTask.java:755)
at
java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I have verified everything looks good and its working as well. As you can see in the attached image it's your above-mentioned code.
Please make sure you added the dependency into your gradle file. If yes, then there may be some issue in some more properly working code here which is overlap on the button. So you need to check in that code.
implementation 'com.google.android.material:material:1.0.0'
After testing the code in other computers the reasons of the error found are-
System support lack - The system used for coding was not able to provide enough resources to render the views efficiently and for which the preview does not work.
Android Studio efficiency - On low capacity systems Android Studio cannot manage dependencies well while rendering and thus throws the error java.lang.IllegalArgumentException: java.lang.ClassCastException
Solution
Optimal solution - Use the recommended system configuration as per documentation.
Ostrich solution - Run the app every-time a change is made on the UI to see how it really works without depending on the Preview

Unable to reproduce Error inflating class TextView

I'm getting next error from crashlytics: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class TextView
Problem is that I'm not able to reproduce this issue and I can only guess why app has crashed while trying to inflate TextView.
This TextView is in drawer_item_1.xml file which is menu item for application drawer.
This issue is reported only on devices running Android version 7.1.1 and 7.1.2 (Nexus 6P, Nexus 5x, Pixel XL and Sony Xperia X)
As I can see there is nothing suspicious here, it is simple TextView with some white text set to be bold, except layout_width is set to wrap_content and should be 0dp because of set layout_weight. Is it possible that this is causing this crashes?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="#drawable/ic_add"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="My String"
android:textColor="#color/white"
android:textStyle="bold"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/rbn_menu_arrow"
/>

Android TextView text cut off only in Gingerbread

The layouts in my application are built using SDK 16 and I've tested and confirmed they work fine on ICS and JB but GB has the following issue:
In the code below, I'm just trying to create a simple layout with only text. The text keeps getting cut off on Gingerbread at the end of the first line though, instead of going on to the next line. I've tried setting singeLine to false, played around with lines, maxLines, marquee, layoutWeight, changing layoutHeight and layoutWidth to every imaginable combination, etc. This issue truly baffles me.
Code:-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text keeps overflowing"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#33B5E5"
android:paddingTop="6dp"
/>
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text gets cut off when I input a long string like this one"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
/>
</LinearLayout>
</ScrollView>
Also, if I change the theme of the layout to Gingerbread, I get the error:
Failed to find style 'scrollViewStyle' in current theme
Failed to find style 'textViewStyle' in current theme
android.content.res.Resources$NotFoundException
Thanks in advance.
Fixed it myself. Couldn't find out why it was happening but I fixed it by adding the following lines to the code for TextViews:-
android:ellipsize="none"
android:maxLines="10"
android:scrollHorizontally="false"

Categories

Resources