android.view.InflateException:二进制XML文件行#11

时间:2011-04-30 19:18:31

标签: android

我有一个带有一些项目的列表视图。当用户触摸第一个列表项时,它会启动一个带有照片的对话活动和下面的一些文本。每个列表项都会发生这种情况。但不幸的是我得到了这个android.view.InflateException: Binary XML file line #11力量错误..这是我的清单的一部分:

  <activity android:name=".kalamaki"
     android:label="Beaches in Chania"                                                      
     android:screenOrientation="portrait"
      android:configChanges="orientation|keyboardHidden"
                android:theme="@android:style/Theme.Dialog"
     />

这是我的.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
        android:background="#cfcfcc"

    >
    <LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<ImageView android:layout_marginTop="5px"
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@+id/image"  
/>

    <TextView   
    android:layout_marginTop="5px"
    android:id="@+id/text"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="@+id/text"
        android:textColor="#262626"
        />

</LinearLayout> 
    </ScrollView>

这是我的logcat错误:

04-30 19:08:34.433: ERROR/AndroidRuntime(405): Uncaught handler: thread main exiting due to uncaught exception
04-30 19:08:34.463: ERROR/AndroidRuntime(405): java.lang.RuntimeException: Unable to start activity ComponentInfo{kostas.menu.chania/kostas.menu.chania.sfinari}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.os.Looper.loop(Looper.java:123)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.ActivityThread.main(ActivityThread.java:4310)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at java.lang.reflect.Method.invokeNative(Native Method)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at java.lang.reflect.Method.invoke(Method.java:521)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at dalvik.system.NativeStart.main(Native Method)
04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.Activity.setContentView(Activity.java:1622)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at kostas.menu.chania.sfinari.onCreate(sfinari.java:15)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     ... 11 more
04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: java.lang.reflect.InvocationTargetException
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.widget.ImageView.<init>(ImageView.java:105)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at java.lang.reflect.Constructor.constructNative(Native Method)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     ... 23 more
04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-mdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x7f050000
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.content.res.Resources.loadDrawable(Resources.java:1710)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.widget.ImageView.<init>(ImageView.java:115)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     ... 27 more
04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: java.io.FileNotFoundException: res/drawable-mdpi/scrollbar_handle_vertical.9.png
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.content.res.AssetManager.openNonAssetNative(Native Method)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.content.res.AssetManager.openNonAsset(AssetManager.java:391)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     at android.content.res.Resources.loadDrawable(Resources.java:1702)
04-30 19:08:34.463: ERROR/AndroidRuntime(405):     ... 29 more

1 个答案:

答案 0 :(得分:1)

您的问题的答案在于您提供的堆栈跟踪:

ERROR/AndroidRuntime(405): Caused by: android.content.res.Resources$NotFoundException: File res/drawable- ...
ERROR/AndroidRuntime(405): Caused by: java.io.FileNotFoundException: res/drawable-mdpi/scrollbar_handle_vertical.9.png

确保scrollbar_handle_vertical.9.png位于res/drawable-mdpi/文件夹

修改 您的android:srcImageView

似乎不适合TextView

应该看起来像:

<ImageView android:layout_marginTop="5px"
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/nameOfTheImage" // <--Change  
/>

    <TextView   
    android:layout_marginTop="5px"
    android:id="@+id/text"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="@string/myText" // <-- Change
        android:textColor="#262626"
        />

因此,在drawable文件夹下,您应该在nameOfTheImage下有一个名为strings.xml的文件和res/values文件中的条目(您更改了任何文件名)名称myText