[英]Android force closes on imageview
In folder res/drawable/ I have stored my image pic.jpg, but the application force closes when I run it on my device. 在文件夹res / drawable /中,我已经存储了图片pic.jpg,但是当我在设备上运行它时,应用程序强制关闭。 The android project was automatically generated, except I have changed the RelativeLayout that encloses everything to a LinearLayout.
android项目是自动生成的,除了我更改了将所有内容封装到LinearLayout的RelativeLayout之外。 Inside of this LinearLayout I have only coded a single ImageView.
在此LinearLayout内部,我只编码了一个ImageView。 The application force closes without displaying anything.
施加力关闭而不显示任何内容。 Please, what am I doing wrong?
拜托,我在做什么错?
Relevant XML: 相关XML:
<ImageView
android:layout_width="85dp"
android:layout_height="85dp"
android:src="@+drawable/pic"
android:contentDescription="@string/none"
/>
Here is the logcat: 这是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
android:src="@+drawable/pic"
should be without a +
sign. 应该没有
+
号。 Accessing /res/drawable
resources is constant - they can't be dynamically generated so having a +
shouldn't work. 访问
/res/drawable
资源是恒定的-它们不能动态生成,因此使用+
无效。
android:src="@drawable/pic"
Also make sure that your pic
picture file is copied into the drawable folder. 还要确保将
pic
图片文件复制 到 drawable文件夹中。 Linking from the filesystem is not the same since the file is not actually in the folder. 由于文件实际上不在文件夹中,因此从文件系统进行链接是不同的。 Linking will result in a
no resource found that matches the given name
error. 链接将导致
no resource found that matches the given name
错误no resource found that matches the given name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.