我制作了一个应用程序,我在我的Samsung android 7.0 API 26上调试它并且效果很好,但只要开始在另一台设备上测试它就会在开始时崩溃并且它会给我这个错误:
FATAL EXCEPTION: main
Process: com.auvray.tasky, PID: 11649
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.auvray.tasky/com.auvray.tasky.LoginActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.auvray.tasky.LoginActivity.onCreate(LoginActivity.java:32)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_person_black_24dp.xml from drawable resource ID #0x7f020070
at android.content.res.Resources.loadDrawable(Resources.java:2136)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:861)
at android.widget.EditText.<init>(EditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:62)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:58)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.auvray.tasky.LoginActivity.onCreate(LoginActivity.java:32)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2132)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:861)
at android.widget.EditText.<init>(EditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:62)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:58)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.auvray.tasky.LoginActivity.onCreate(LoginActivity.java:32)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
我不知道发生了什么,因为它在我的三星上工作得很好但是只要我尝试我的LG就崩溃了,我看到它由我的登录XML文件引起的错误但是那里没有错误:
activity_login.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:padding="20dp"
android:background="@drawable/login_background"
>
<ImageView
android:layout_gravity="center"
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5"
app:srcCompat="@drawable/logo_backg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<EditText
android:id="@+id/name_login_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_person_black_24dp"
android:drawableStart="@drawable/ic_person_black_24dp"
android:drawablePadding="10dp"
android:ems="10"
android:hint="@string/username"
android:inputType="textPersonName"
android:padding="10dp"
android:textSize="25sp" />
<EditText
android:id="@+id/pass_login_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_https_black_24dp"
android:drawableStart="@drawable/ic_https_black_24dp"
android:drawablePadding="10dp"
android:ems="10"
android:hint="@string/password"
android:inputType="textPassword"
android:padding="10dp"
android:textSize="25sp" />
<Button
android:id="@+id/login_login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/LOGINN"
android:textSize="25sp"/>
<TextView
android:id="@+id/forg_pass_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/forgot"
android:textSize="17sp"
android:gravity="center"/>
<TextView
android:id="@+id/offline_login_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/offline"
android:textColor="@android:color/holo_red_dark"
android:textSize="25sp"
android:visibility="invisible" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/noaccTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/noaccount"
android:textSize="17sp"/>
<TextView
android:id="@+id/signupTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signup"
android:textStyle="bold"
android:textSize="17sp"/>
</LinearLayout>
是否有人可以告诉我错误是什么以及为什么它在我的另一台设备上运行时会崩溃? 非常感谢。
答案 0 :(得分:0)
问题很可能是您以不受支持的方式使用矢量drawable。由于您发布的错误表明系统无法使EditText
膨胀,我只能假设@drawable/ic_person_black_24dp
是一个可绘制的矢量。
您可以在ImageView
中使用向量的原因是您正在使用app:srcCompat
属性,该属性实际上是AppCompatImageView
的属性。对于TextView
及其子类(例如EditText
和Button
),android:drawableLeft
(以及顶部/右侧/底部)属性不支持向量绘制。
最简单的解决方案是用.png文件替换vector drawable。您还可以修改布局,在ImageView
旁边添加EditText
,以便使用app:srcCompat
属性。