Android - put an image name “package” throws compile time error

▼魔方 西西 提交于 2019-12-08 17:05:39

问题


I am trying to put an image name "package.png" in my drawable folder. As soon as i paste them it into the folder it is throwing following error:

[2012-05-26 12:40:30 - MyApp] res/drawable-mdpi/package.png:0: error: invalid symbol: 'package'

But as soon as i rename to some other name, this image works fine. Any idea why this is happening and how i can fix this and have a drawable named "package".


回答1:


you cant do that, as it is a Reserved word. just like...

break else new var
case finally return void
catch for switch while
continue function this with
default if throw
delete in try
do instanceof typeof
abstract enum int short
boolean export interface static
byte extends long super
char final native synchronized
class float package throws
const goto private transient
debugger implements protected volatile
double import public
null
true
false

Each resource having entry in java field name inside R.java class:

drawable\package.png -> R.drawable.package // while package is a reserved keyword in Java(mentioned above)


来源:https://stackoverflow.com/questions/10764347/android-put-an-image-name-package-throws-compile-time-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!