在eclipse中导入工程后 出现下图的错误:

上图中的代码出现这样的情况,是因为R.java文件中定义属性的方式为:public static int xxx = 0x7f0a0003; 而自从adt14开始,R.java文件定义属性的方式有发生了变化:public static final int xxx =0x7f0a0003; 所以使用switch...case语句来定位id这样的代码将不再编译,解决办法是选中switch这个keyword,按ctrl + 1将代码块转换为if...else,问题解决!
google官方给出的解释是:
In a regular Android project, constants in the resource R class are declared like this:
publicstaticfinalintmain=0x7f030004;
However, as of ADT 14, in a library project, they will be declared like this:
public static int main=0x7f030004;
The solution for this is simple: Convert the switch statement into an if-else statement. Fortunately, this is very easy in Eclipse. Just place the caret on the switch keyword, and press Ctrl-1 (or Cmd-1 on Mac):
详情参见: http://tools.android.com/tips/non-constant-fields
解决Eclipse中导入工程后R.java文件错误问题
在Eclipse中导入工程后遇到R.java文件错误,原因是ADT14版本开始调整了资源类定义方式。文章提供了解决方案,即在switch语句处使用if-else替代,通过Eclipse快捷操作实现转换。

7317

被折叠的 条评论
为什么被折叠?



