Android力量在imageview上关闭

时间:2013-03-13 17:08:25

标签: android

在文件夹res / drawable /我已经存储了我的图像pic.jpg,但是当我在我的设备上运行时,应用程序强制关闭。 android项目是自动生成的,除了我已经更改了包含所有内容的RelativeLayout到LinearLayout。在这个LinearLayout内部,我只编写了一个ImageView。申请人关闭而不显示任何内容。拜托,我做错了什么?

相关XML:

<ImageView
    android:layout_width="85dp"
    android:layout_height="85dp"
    android:src="@+drawable/pic"
    android:contentDescription="@string/none" 
/>

这是logcat:

03-13 12:56:54.920: E/AndroidRuntime(21033): FATAL EXCEPTION: main
03-13 12:56:54.920: E/AndroidRuntime(21033): java.lang.RuntimeException: Unable to     start activity ComponentInfo{com.example.imageshow/com.example.imageshow.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class   android.widget.ImageView
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.os.Looper.loop(Looper.java:130)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.ActivityThread.main(ActivityThread.java:3691)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at java.lang.reflect.Method.invokeNative(Native Method)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at java.lang.reflect.Method.invoke(Method.java:507)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at dalvik.system.NativeStart.main(Native Method)
03-13 12:56:54.920: E/AndroidRuntime(21033): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.widget.ImageView
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.Activity.setContentView(Activity.java:1679)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at com.example.imageshow.MainActivity.onCreate(MainActivity.java:12)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-13 12:56:54.920: E/AndroidRuntime(21033):    ... 11 more
03-13 12:56:54.920: E/AndroidRuntime(21033): Caused by: java.lang.reflect.InvocationTargetException
03-13 12:56:54.920: E/AndroidRuntime(21033):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
03-13 12:56:54.920: E/AndroidRuntime(21033):    ... 22 more
03-13 12:56:54.920: E/AndroidRuntime(21033): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=3 r=0x7f020001}
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.content.res.Resources.loadDrawable(Resources.java:1907)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.content.res.TypedArray.getDrawable(TypedArray.java:653)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.widget.ImageView.<init>(ImageView.java:118)
03-13 12:56:54.920: E/AndroidRuntime(21033):    at android.widget.ImageView.<init>(ImageView.java:108)
03-13 12:56:54.920: E/AndroidRuntime(21033):    ... 25 more

1 个答案:

答案 0 :(得分:1)

android:src="@+drawable/pic"

应该没有+标志。访问/res/drawable资源是不变的 - 它们无法动态生成,因此+不应该有效。

android:src="@drawable/pic"

还要确保您的pic图片文件已复制 可绘制文件夹中。从文件系统链接是不一样的,因为该文件夹中的文件实际上。链接会导致 no resource found that matches the given name 错误。