android项目变为library项目的问题和解决
来源:互联网 发布:万国数据员工待遇 拉勾 编辑:程序博客网 时间:2024/04/28 23:59
最近在合并项目的时候,发现一个原来正常的android项目变为library项目后,出现了错误提示:
case expressions must be constant expressions
error on case
.
@Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { switch (item.getItemId()) { case R.id.about: //error startActivity(new Intent(this, AboutActivity.class));
解决:
I've replaced the switch/case
statement with if/else
. You can just click on switch
and then press CTRL+1
if you're in Eclipse.
http://stackoverflow.com/questions/14858328/switch-case-expressions-must-be-constant-expressions
Take a look at the official blog post about this:
http://tools.android.com/recent/switchstatementconversion
http://tools.android.com/tips/non-constant-fields
Basically, resource constants in library projects are no longer "final". From the ADT Site:
In other words, the constants are not final in a library project. The reason for this is simple: When multiple library projects are combined, the actual values of the fields (which must be unique) could collide. Before ADT 14, all fields were final, so as a result, all libraries had to have all their resources and associated Java code recompiled along with the main project whenever they were used. This was bad for performance, since it made builds very slow. It also prevented distributing library projects that didn't include the source code, limiting the usage scope of library projects.
so if you the the fix it will convert switch into if and else...
int id = view.getId();if (id == R.id.button1) { action1();} else if (id == R.id.button2) { action2();} else if (id == R.id.button3) { action3();
参考:
http://stackoverflow.com/questions/17849566/switch-case-expressions-must-be-constant-expressions-i-cant-make-the-if-else
http://tools.android.com/recent/switchstatementconversion
Switch Statement Conversion
posted Sep 29, 2011, 2:35 PM by Tor Norbye- android项目变为library项目的问题和解决
- Android项目Library导入的问题整理
- 解决maven web项目倒入eclipse不出现Maven Dependencies 和 Java System Library的问题
- 解决Maven项目在update时,变为默认用java1.5编译的问题
- 解决:Maven项目,右键-update project后JRE system Library变为JavaSE1.5
- Eclipse中Maven项目执行Maven update project 项目JRE System Library变为1.5的解决办法
- 解决windows下eclipse中android项目关联android library project失败问题
- 解决windows下eclipse中android项目关联android library project失败问题
- 解决windows下eclipse中android项目关联android library project失败问题
- 解决eclipse中android项目关联android library project失败问题
- 解决windows下eclipse中android项目关联android library project失败问题
- Maven 项目生成或者update jdk变为1.5的问题
- Maven 项目生成或者update jdk变为1.5的问题
- Maven 项目生成或者update jdk变为1.5的问题
- ADT_20新建项目Android Support library not installed问题【已解决】
- 解决windows下eclipse中android项目关联 library 失败问题
- Android Studio 中创建一个Library 的module 和导入一个Library项目
- Android:项目关联Library
- 不被理解的毛泽东(谈高、粟、彭、刘、林、周、蒋之平生)1
- sql语句的执行顺序
- mysql分区功能详细介绍,以及实例
- 源码编译mysql5.5过程记录
- jq放大镜(好久没写了。差点儿忘了。找个文章)
- android项目变为library项目的问题和解决
- restlet上传图片代码
- vs2010 失效后的解决办法
- 站外优化
- 使用Java向properties存数据
- 关于YAML
- iOS 屏幕方向
- myeclipse 文件默认打开方式设置
- RT Shader System in OGRE 1.7.0 .