[英]How to add images in res folder in android
I am trying to add some images to res folder in my android 4.2.2 application. 我正在尝试将一些图像添加到我的android 4.2.2应用程序的res文件夹中。 The problem is the project runs fine until whenever I do add, upon running it gives an error 问题是项目运行正常,直到我每次添加时,运行时都会出现错误
R cannot be resolved to a variable
in the src/MainActiviy.java
and the R.java
file deletes it self from the gen
folder. 在src/MainActiviy.java
,并且R.java
文件从gen
文件夹中将其自身删除。
Now I'm naming the folder drawable-mdp
and every png
image is also lower cased. 现在,我为文件夹drawable-mdp
命名,每个png
图像也都小写。 But it doesn't seem to bother. 但这似乎并不麻烦。 Thanks! 谢谢!
You are getting this error because R.java
failed to create. 您收到此错误,因为R.java
创建失败。 This happens when you try to a non-png image or the name of image contains some special character or characters in uppercase. 当您尝试使用非png图像或图像名称包含一些特殊字符或大写字符时,会发生这种情况。
Ok guys I did try a few things and I finally got it. 好的,我确实尝试了几件事,终于知道了。 You can't use -
hyphen while naming the image files themselves however _
underscore can be used. 您不能在命名图像文件本身时使用-
连字符,但是可以使用_
下划线。 Note you always have to use drawable- while naming the folder can't use _
underscore 请注意,您始终必须使用drawable-,同时命名文件夹时不能使用_
下划线
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.