资源$ NotFoundException:来自可绘制资源.xml扩展名的文件res / drawable-xxhdpi-v4 / toast_frame.9.png

时间:2016-10-13 18:52:52

标签: java android user-interface

我设计了一个没有任何功能的单个活动,只是为了查看UI是否会加载到我的VM(api24)中。它会加载一个空白活动,在加载任何字段之前,它会因以下错误而崩溃:

              --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.freek_000.bluetoothatendee, PID: 2450
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.freek_000.bluetoothatendee/com.example.freek_000.bluetoothatendee.MainActivity}: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class EditText
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6077)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
               Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class EditText
               Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class EditText
               Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xxhdpi-v4/toast_frame.9.png from drawable resource ID #0x1080096: .xml extension required
                  at android.content.res.ResourcesImpl.loadComplexColorForCookie(ResourcesImpl.java:935)
                  at android.content.res.ResourcesImpl.loadComplexColorFromName(ResourcesImpl.java:756)
                  at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:835)
                  at android.content.res.Resources.loadColorStateList(Resources.java:998)
                  at android.content.res.TypedArray.getColorStateList(TypedArray.java:531)
                  at android.view.View.<init>(View.java:4488)
                  at android.widget.TextView.<init>(TextView.java:710)
                  at android.widget.EditText.<init>(EditText.java:64)
                  at android.widget.EditText.<init>(EditText.java:60)
                  at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:59)
                  at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:55)
                  at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
                  at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1013)
                  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1072)
                  at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                  at com.example.freek_000.bluetoothatendee.MainActivity.onCreate(MainActivity.java:11)
                  at android.app.Activity.performCreate(Activity.java:6664)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6077)
                  at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

SDK中出现的预定义类中出现了很多错误。这是一个全新安装的Android Studio,带有一个新的项目文件。这是一个已编辑的空白活动。这是它的XML:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.freek_000.bluetoothatendee.MainActivity">

<TextView
    android:text="       Login"
    android:layout_width="350dp"
    android:layout_height="75dp"
    android:layout_marginTop="35dp"
    android:id="@+id/tLogin"
    android:textAppearance="@style/TextAppearance.AppCompat.Display3"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_marginTop="32dp"
    android:id="@+id/editText"
    android:hint="Jag Number"
    android:backgroundTint="@android:drawable/toast_frame"
    android:background="@android:drawable/toast_frame"
    android:textColorHint="@android:color/background_light"
    android:layout_below="@+id/tLogin"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/tPassword"
    android:backgroundTint="@android:drawable/toast_frame"
    android:background="@android:drawable/toast_frame"
    android:hint="Password"
    android:textColorHint="@android:color/background_light"
    android:layout_centerVertical="true"
    android:layout_alignLeft="@+id/editText"
    android:layout_alignStart="@+id/editText" />

<Button
    android:text="Login"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:id="@+id/bLogin"
    android:layout_below="@+id/tPassword"
    android:layout_centerHorizontal="true" />

<Button
    android:text="Register"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="18dp"
    android:id="@+id/bRegister"
    android:layout_below="@+id/bLogin"
    android:layout_alignLeft="@+id/bLogin"
    android:layout_alignStart="@+id/bLogin" />

2 个答案:

答案 0 :(得分:1)

问题是由于编辑的文字无法使用背景。删除edittext字段的背景,它加载并运行正常

答案 1 :(得分:0)

我认为这个解决方案不是很好;你的崩溃是因为你引用了错误的包;

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/tPassword"
    android:backgroundTint="@drawable/toast_frame"
    android:background="@drawable/toast_frame"
    android:hint="Password"
    android:textColorHint="@color/background_light"
    android:layout_centerVertical="true"
    android:layout_alignLeft="@+id/editText"
    android:layout_alignStart="@+id/editText" />

"@android" 表示您想构建内部资源。但 "toast_frame" 来自您的应用。