Unable to reproduce Error inflating class TextView - android

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"
/>

Related

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

Inflating layout XML on Android

I have error inflating button in XML. It's quite unique, among 10k users only couple of crashes. One for Android 9, another Android 8. Devices are Google Pixel 2l and Nexus 5x.
So I guess in general code is fine, but no ideas how to debug on specific devices.
Fatal Exception:
> java.lang.RuntimeException Unable to start activity ComponentInfo{}:
> android.view.InflateException: Binary XML file line #21: Binary XML
> file line #21: Error inflating class Button
> android.app.ActivityThread.performLaunchActivity
This is the Button
<Button
android:id="#+id/constraintLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="16dp"
android:background="#color/colorAccent"
android:drawableStart="#drawable/navigation_back"
android:onClick="backListener"
android:stateListAnimator="#null"
android:text="#string/survey_register_driver"
android:textAllCaps="false"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</Button>

Error: " android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class <unknown> "

When working with 4.7 WXGA API 23, I am getting the error of "android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class "
but in higher versions, it is all working well, I have added the code and the xml layout for my issue, don't understand why it is happening so
Code where this error is occurring
#NonNull
#Override
public PostsHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_list_layout,
parent, false);
return new PostsHolder(v);
}
XML Layout for recyclerview Item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/shadow_300_50"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:padding="5dp"
android:orientation="horizontal"
>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/profile"
android:id="#+id/post_user_profile_image"
android:scaleType="centerCrop"
android:layout_marginLeft="4dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:id="#+id/post_item_username"
android:layout_marginLeft="5dp"
android:layout_marginTop="8dp"
android:textAlignment="textStart"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#android:color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Time"
android:id="#+id/post_item_time"
android:layout_marginLeft="257dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:textAlignment="textStart"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#android:color/black"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:id="#+id/post_item_title"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textAlignment="textStart"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#android:color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="5dp"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="post_item_Category"
android:textColor="#color/colorPrimaryDark"
android:textSize="13sp"
android:textStyle="bold"
android:id="#+id/post_item_Category"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Post_item_SpinnerC"
android:textColor="#color/colorPrimaryDark"
android:textSize="13sp"
android:id="#+id/post_item_SpinnerC"
android:layout_marginLeft="7dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/post_item_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="3dp"
android:padding="3dp"
android:text="Post Description"
android:textColor="#android:color/black"
android:textSize="14dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:padding="2dp">
<Button
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mark"
app:srcCompat="#drawable/ic_heart_normal"
android:background="#drawable/button"/>
<Button
android:id="#+id/commenting_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="140dp"
android:text="Comment"
android:background="#drawable/button"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
The problem is that a constructor for a class for creating one of the widgets doesn't exist or can't be found. The LayoutInflater class (in the sdk, ie: Android\Sdk\sources\android-17\android\view\LayoutInflater.java) uses reflection(code introspection) on the widget name to build the widget object. In your case I would guess it is 'de.hdodenhof.circleimageview.CircleImageView', in my case it was 'androidx.appcompat.widget.Toolbar'.
Finding the problem is buried in several layers of exceptions, and only the (pretty useless) 'Binary XML file line #7: Error inflating class...' message appears. I set up Android Studio to break on the android.view.InflateException exception:
The 'ie' InflateException at the bottom contains a java.lang.reflect.InvocationTargetException, which was in turn caused by a android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f03008f a=-1} exception (in my case)
In the LayoutInflator code:
Lin 616 is where they embed the exception named 'e' in the InflationException. Using the 'Evaluate Expression' feature of AS, I called 'e.getStackTrace()' which shows where the error really occurred:
StackTrace line 2 shows that it was line LayoutInflater line 587 (seen with red background in code image above) that threw the exception. Looking up to stackTrace line 0, it is the java.lang.reflect.Constructor.constructNative method that threw the original exception.
LayoutInflator line 587 is was trying to instanciate androidx.appcompat.widget.Toolbar (for me) and was looking for a Toolbar constructor with 2 arguments:
1) Context: ref to activity in which the layout was being inflated
2) AttributeSet: the opaque XmlBlock object named 'attrs'
I found this out by using Expression Evaluator on 'this.mConstructorArgs' (seen in line 584 of the code).
So, for me, it could not find a constructor with the Toolbar(Activity, XmlBlock) signature. So I have to look into where Toolbar is defined in by configuration and find out what constructors it has.
The usual 'solution' people give as in this question, is to clear caches, reset support libraries, run with the latest dependencies etc, which don't get you to the root cause, and sometimes don't work.
I'm documenting this here somewhat for my own future problems -- and also as a plea to the Android developers to give clearer error messages. 'Binary XML file line #7: Error inflating' doesn't help much and line 7 of some Binary XML file doesn't give and clues.
#ramneek, 'de.hdodenhof.circleimageview.CircleImageView' is the only unusual widget you are inflating there must be some method or constructor for that class/widget that the inflator can't find.

Unable to start activity android.view.InflateException: Binary XML file line #14: Error inflating class fragment

I realize that there are a lot of questions with titles similar to this one, but I think my problem is one that has not yet been addressed.
I have an existing Android application that is entering the intensive beta-testing phase. To that end, I am attempting to implement Instabug to help out.
This morning, before attempting to implement Instabug, my app worked (in that it launched).
My MainActivity extends android.app.Activity, so I replaced that with InstabugActivity (com.instabug.wrapper.support.activity.InstabugActivity).
My MainActivity is for login/sign up, and then the app transitions to an AppRootActivity, which is an android.support.v7.app.ActionBarActivity. This is because the app has a navigation drawer. So, I changed AppRootActivity to an InstabugActionBarActivity (com.instabug.wrapper.support.activity.InstabugActionBarActivity).
When I run the app in debug mode using an attached device, it works just fine. When I push the app out to my testers via Fabric/Crashlytics, the app crashes at launch.
From what I can tell, these are the important error messages I'm getting:
java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.company.app/com.company.app.MainActivity}:
android.view.InflateException: Binary XML file line #14:
Error inflating class fragment
Caused by:
android.view.InflateException: Binary XML file line #14:
Error inflating class fragment
at com.company.app.MainActivity.onCreate(Unknown Source)
Caused by:
android.app.Fragment$InstantiationException:
Trying to instantiate a class
com.company.app.NavigationDrawerFragment
that is not a Fragment
    at com.company.app.MainActivity.onCreate(Unknown Source)
Caused by: java.lang.ClassCastException
at com.company.app.MainActivity.onCreate(Unknown Source)
Ok, now here's the weird thing. MainActivity is never tied to NavigationDrawerFragment. Never.
I have no idea why the app is trying to instantiate NavigationDrawerFragment when the app is launching.
Even still, though, NavigationDrawerFragment extends MyFragment which extends Fragment (android.support.v4.app.Fragment).
I am really, really lost here. I'd love to use Instabug, because their product on iOS is really nice and impressive, but I can't figure this out!
Edit
Here's the XML layout for ActivityMain:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/main_activity_background"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
<View
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
/>
<ImageView
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:src="#drawable/main_activity_logo"
/>
<View
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
/>
<TextView
android:id="#+id/main_activity_tag_line_text_view"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:text="#string/tag_line"
android:textColor="#color/off_white"
android:textSize="20dp"
/>
<ImageButton
android:id="#+id/main_activity_sign_up_with_Facebook_button"
android:background="#drawable/main_activity_facebook_button_shape"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/main_activity_vertical_button_margin"
android:layout_marginTop="#dimen/main_activity_vertical_button_margin"
android:layout_width="wrap_content"
android:paddingBottom="#dimen/main_activity_facebook_sign_up_button_vertical_padding"
android:paddingLeft="#dimen/main_activity_facebook_sign_up_button_horizontal_padding"
android:paddingRight="#dimen/main_activity_facebook_sign_up_button_horizontal_padding"
android:paddingTop="#dimen/main_activity_facebook_sign_up_button_vertical_padding"
android:src="#drawable/main_activity_facebook_sign_up"
/>
<Button
android:id="#+id/main_activity_sign_up_button"
android:background="#drawable/sign_up_button_shape"
android:gravity="center"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/main_activity_vertical_button_margin"
android:layout_marginTop="#dimen/main_activity_vertical_button_margin"
android:layout_width="wrap_content"
android:text="#string/sign_up_title"
android:textColor="#color/dark_gray"
android:textSize="#dimen/login_button_text_size"
/>
<Button
android:id="#+id/main_activity_login_button"
android:background="#drawable/main_activity_login_button_shape"
android:gravity="center"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/main_activity_vertical_button_margin"
android:layout_marginTop="#dimen/main_activity_vertical_button_margin"
android:layout_width="wrap_content"
android:text="#string/login_title"
android:textColor="#color/gold"
android:textSize="#dimen/login_button_text_size"
/>
<TextView
android:id="#+id/main_activity_disclaimer_text_view"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_width="wrap_content"
android:text="#string/disclaimer"
android:textColor="#color/off_white"
android:textSize="12dp"
/>
</LinearLayout>

Sliding Tab layout not working in Pre - Lollipop Devices but working fine in Lollipop Devices

I am using SlidingTabLayout,its working fine in Lollipop devices but when I m trying to run in pre-lollipop devices its showing an error
"android.view.InflateException: Binary XML file line #2: Error inflating class
at android.view.LayoutInflater.createView"
But I have made another Project having same codes, in that SlidingTabLayout is working fine in both lollipop and pre-lollipop devices.
I m not getting whats the prob, same code but not working.
Please help me.
This is the XML layout code of the custom layout for the Tab.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="#drawable/tab_bg"
android:orientation="vertical">
<ImageView
android:id="#+id/tabImage"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tabText"
android:gravity="bottom|center"
android:textSize="14sp"
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

Categories

Resources