adt版本升级后,不支持switch...case语句的解决办法

在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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值