#30行出现错误,即所提供代码中第一个EditText的第一行。该XML基本上与活动相关联。错误是在活动中绑定XML时
setContentView(R.layout.activity_login)
错误如下:
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)
我尝试了其他答案中解释的几件事,但没有一个实际上对我有帮助。我没有为该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窗口小部件应正常加载,但活动因上述错误而崩溃。
提供其他信息:
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'
答案 0 :(得分:0)
如果它的向量是奇巧,则应以编程方式设置left drawable。
company_code.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,R.drawable.ic_store_white_24dp), null, null, null);```
答案 1 :(得分:-1)
您使用的是哪个android版本,我认为您在EditText
中使用了Vector Drawable,但是在KitKat
之后使用了Vector Drawable。