Can anyone tell me whats wrong with this layout? Because I can't seem to find anything unusual that could cause InflateException. Also I am getting this exception mostly on Samsung Devices, others seem to work more or less fine. Full exception
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{class name}: android.view.InflateException: Binary XML file line #0: Error inflating {class name}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/loginContainer"
style="#style/AuthenticationTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0">
<LinearLayout
android:id="#+id/holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="#string/window_enter_identifier_greeting_label"
android:textAlignment="center"
android:textSize="26sp" />
<TextView
android:id="#+id/info"
style="#style/AuthenticationTheme"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="#dimen/authentication_margin_from_sides"
android:layout_marginRight="#dimen/authentication_margin_from_sides"
android:gravity="center"
android:text="#string/window_enter_identifier_phone_description_label"
android:textAlignment="center"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/phoneInputHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.custom.authentication.views.IdentifierInputView
android:id="#+id/authenticationInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/authentication_margin_from_sides"
android:layout_marginRight="#dimen/authentication_margin_from_sides" />
</LinearLayout>
</LinearLayout>
<com.custom.authentication.views.BottomButtonsView
android:id="#+id/bottomButtons"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:linkText="#string/window_enter_identifier_login_with_email_button"
app:mainText="#string/Continue" />
</android.support.constraint.ConstraintLayout>
I am inflating this layout in my custom view class like this:
class EnterIdentifierView(context: Context) : ConstraintLayout(context) {
init {
inflate(context, R.layout.view_enter_identifier, this)
}
And creating my custom view like this:
override fun onCreateControllerView(layoutInflater: LayoutInflater, viewParent: ViewGroup) = EnterIdentifierView(layoutInflater.context)
I don't think this is an answer, more of a suggestion, but as I don't have enough reputation have to post it as such.
From my experience when I get this type of error it sometimes indicates an OutOfMemory error, check to make sure your custom classes aren't trying to load any large images etc.
Also check the full Stacktrace carefully, if you have access to one, for any OOMs
Related
I am new to Android Studio. I started building an app. This is the code of my xml file. I can't figure out the problem! This is the exact error code that I am getting."ParseError at [row,col]:[60,1]
Message: XML document structures must start and end within the same entity."
<?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"
android:background="#121212"
tools:context=".MainActivity"
>
<ImageView
android:id="#+id/imageView"
android:layout_width="844dp"
android:layout_height="1090dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.988"
app:srcCompat="#drawable/up_notch_adobespark" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="50dp"
android:layout_height="54dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.005"
tools:srcCompat="#drawable/more_button" />
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="59dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.997"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.004"
app:srcCompat="#drawable/help_icon" />
<TextView
android:id="#+id/textView"
android:layout_width="165dp"
android:layout_height="36dp"
android:fontFamily="#font/baloo_tamma"
android:text="Hi Josh."
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.158" />
just like broot explained … XML syntax is similar to HTML it has an opening and closing tag, so you need to close every single tag you open in which your case is the constraint layout . just add this line to the end of your xml file
</androidx.constraintlayout.widget.ConstraintLayout>
another advice would be very useful is to avoid using horizontal and vertical bias, I believe that padding(s) and margins(s) are more than enough to help you design the layout you want
and try also using for width and height wrap_content or match parent for detailed and correct measurement for the most phones that will be used. because if you changed the amuleter you are using you will notice that the measurement will be diffrient so as a best practice is to use wrap_content or match parent
Error message is pretty self-explanatory. You opened ConstraintLayout tag at the beginning of the document, but you never closed it. You need to add the following at the end:
</androidx.constraintlayout.widget.ConstraintLayout>
<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
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.
1) I'm seeing "unknown drawble resource" error when I use:"android:src="#drawble/party""
The complete code is shown below. What's the issue as my "party.jpg" file is under res/drawble folder?
2) I also see an error with "android:layout_alignRight="8dp"" What's the issue here?
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="park.hannah.myapplication.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawble/party" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From. Hyunji"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Tuesday!!"
android:layout_alignRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
YOU HAVE SYNTAX ERROR
#drawable/party instead of #drawble/party
use this
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/party" />
I also see an error with "android:layout_alignRight="8dp"" What's the
issue here?
you must align a view depend on another view by ID
suggestions
you can also use gravity right instead of android:layout_alignRight for not complex view layouts
try to use LinearLayout easy and comfort for not complex view layouts
rename your drawable from *.jpg to *.png
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>