-1

I am getting following error for the line #30 i.e. first line of first EditText in the provided code. This XML is basically associated with an Activity. The error is while binding XML inside activity

setContentView(R.layout.activity_login)

The error is as follows:

Caused by android.view.InflateException: Binary XML file line #30: Binary XML file line #30: Error inflating class EditText
       at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
       at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
       at com.pockethcm.greytrix.test.LoginActivity.onCreate(LoginActivity.kt:39)
       at android.app.Activity.performCreate(Activity.java:6268)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2370)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2477)
       at android.app.ActivityThread.-wrap11(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5468)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:671)

I have tried couple of things explained in other answers but none of them actually helped me. I am not using any drawable resource for that EditText.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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:background="@drawable/login_bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.pockethcm.greytrix.test.LoginActivity"
    >
    <LinearLayout
        android:layout_gravity="center_vertical"
        android:gravity="center_vertical"
        android:paddingStart="@dimen/_20sdp"
        android:paddingEnd="@dimen/_20sdp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/login_layout">

        <de.hdodenhof.circleimageview.CircleImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/profile_image"
            android:layout_width="match_parent"
            android:layout_height="96dp"
            android:src="@drawable/pocketlogosplash"
            app:civ_border_width="2dp"
            app:civ_circle_background_color="@color/colorWhite"
            app:civ_border_color="#bcbcbc"/>

        <EditText
            android:layout_width="match_parent"
            android:backgroundTint="@color/colorWhite"
            android:layout_height="wrap_content"
            android:hint="Company Code"
            android:textColorHint="@color/colorWhite"
            android:layout_marginTop="20dp"
            android:drawableStart="@drawable/ic_store_white_24dp"
            android:drawablePadding="10dp"
            android:textColor="@color/colorWhite"
            android:id="@+id/company_code"
            android:imeOptions="actionNext"
            android:maxLines="1"
            android:singleLine="true"/>

        <EditText
            android:layout_width="match_parent"
            android:backgroundTint="@color/colorWhite"
            android:layout_height="wrap_content"
            android:hint="Employee Code"
            android:textColorHint="@color/colorWhite"
            android:layout_marginTop="20dp"
            android:drawableStart="@drawable/ic_person_black_24dp"
            android:drawablePadding="10dp"
            android:textColor="@color/colorWhite"
            android:id="@+id/employee_code"
            android:drawableTint="@color/colorWhite"
            android:imeOptions="actionNext"
            android:maxLines="1"
            android:singleLine="true"/>

    </LinearLayout>
</ScrollView>

EditText widget should load normally but the activity is crashing with error above.

Providing additional info:

compileSdkVersion 28
minSdkVersion 21
targetSdkVersion 28

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
bhushan2k
  • 1
  • 3
  • Please [edit] your question to provide the complete [stack trace](https://stackoverflow.com/a/23353174). – Mike M. May 13 '19 at 05:53
  • checkout [this aswer](https://stackoverflow.com/questions/4512981/android-view-inflateexception-binary-xml-file-line-12-error-inflating-class) – P.Juni May 13 '19 at 06:11
  • No, not the build info. We need the complete stack trace, that whole section of red lines that starts with `Caused by android.view.InflateException`, that you copied the first part of, from the logs. – Mike M. May 13 '19 at 06:17
  • If I am not wrong, stack trace the complete process of code execution till the actual error occurs from the link you have provided. But, as you can see my post, I am not executing anything on that Activity but just binding XML layout at setContentView which is the first line of execution in onCreate method of activity. How do I provide stack trace if I am not executing any code but just binding XML. – bhushan2k May 13 '19 at 06:29
  • It doesn't matter whether it's your code executing, or framework code. There is more to that stack trace. `InflateException` is just a wrapper `Exception` that only tells you that _something_ went wrong while converting the XML to UI objects. There is an underlying `Exception` and message that will be more specific. – Mike M. May 13 '19 at 06:45

2 Answers2

0

You should set left drawable programmatically if its vector for pre kitkat.

company_code.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,R.drawable.ic_store_white_24dp), null, null, null);```
RKRK
  • 1,284
  • 5
  • 14
  • 18
-1

Which android version you are using, I think you use Vector Drawable in EditText, But Vector Drawable support after KitKat.

RKRK
  • 1,284
  • 5
  • 14
  • 18
  • Tesing on API 28 (Android 9 Emulator). Edited OP with some additional info. And I am not using any Vector Drawable in EditText but png image at drawableStart. – bhushan2k May 13 '19 at 06:17
  • I check your code in my machine without drawbles and colors, it's working fine. – Harish Singhania May 13 '19 at 06:21
  • It is working fine on my phone as well. Thing is I am working in a company and I have integrated Fabric.io crashlytics inside app I am working on. So whenever any client gets any problem like crashes with app, the logs (like the one I have provided) are updated on fabrics.io. I copied that log and posted here. Wondering why this code is working fine on my testing devices but clients. That's the reason I am not able to fix it since I am not getting error on my devices. – bhushan2k May 13 '19 at 06:27