android学习—— Android导入源代码出现Remove @Override问题解决方法 .
2013-03-27 13:17
573 查看
有时候我们导入一个Android项目到Eclipse中,会出现很多错误提示,但基本都是要我们把 @Override Remove掉![]() 这个一般是因为配置文件中的JDK版本不对导致的 配置文件就是工程目录下.settings文件夹中org.eclipse.jdt.core.prefs文件 我们如果用UEdit或记事本打开他可以看到里面的代码是这样的 #Wed Mar 21 16:05:12 CST 2012 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.5 复制代码 可以看到这里的配置是JDK1.5 我们如果手动将这里的1.5都修改成1.6 然后Refresh下项目就可以了 还有个方法就是 看下面的图吧 ![]() 这样有些情况可以解决 有时候不行 然后继续下面的操作 ![]() ![]() ![]() 改成1.6 然后保存 ![]() ![]() 问题应该都解决了 Eclipse里import 一个可运行的 project经常遇到的一个问题:报一大堆错,当解决了引入jar包、sdk问题后,发现好多error都有一个共同的要求:“remove @Override Annotation”。 How to get rid of all these "remove @Override Annotation" errors? Is there a way to just comment out all the @Overrides that turn out to be Eclipse errors that prevent your app from building/running? Solutions: (1)思路一:There are already @Override annotations in the source code, now I am getting compile errors on them. www.2cto.com 不是SDK的问题(SDK引入正确,排除),难道是JDK? project上右击-->Properties-->Java Compiler, 显示当前我的Compiler compliance level为1.5,修改为1.6,警报解除。 问题1:我明明安装的jdk1.7,compiler compliance level为什么是1.5呢? compiler compliance level的含义说明:设置编译级别。 Eclipse compiler compliance level为较低版本,只是让编译器相信你的代码是兼容较低版本的,在编译时生成的bytecode(class)兼容较低版本。这样设置与你写代码时引用的JDK是没关系的,也就是说你在写代码时仍可以引用较高版本的API(这样就可能导致错误)。 设置compiler compliance level为较低版本,这样的好处是当别人使用了较低版本的Jdk时也可以引用你写的编译后的代码。它可以保证编译后的class文件的版本一致性。但是,如果你的代码里面(java source)里面调用了较高版本jdk的API.那么即使设置了compiler compliance level为较低版本,在较低版本的JDK上运行你的代码也会报错。所以建议在写代码时引用的JDK,要跟你compiler compliance level设置的版本,是一致。 问题2:为什么修改为1.6就不再警报了呢? You need at least jdk1.5 to use those annotations on methods derived from classes. You need at least jdk1.6 to use those annotations on methods derived from interfaces. (2)思路二:修改Eclipse警报级别 Window-->Preferences-->Java-->Compiler-->Errors/Warnings-->Annotations Under there, check that the"Missing '@Override' annotation is set to "Ignore" or "Warning" and not "Error"。 Edit:I wanted to add that you can get Eclipse to automatically add @Override annotations on files that you save in the Save Actions。 Window-->Preferences-->Java-->Editor-->Save Actions There is a checkbox for "Additional Actions" and if you open the "Configure" window you can select the "Missing Code" tab and select "Add Missing Annotations" where you can select which annotations to automatically add. (3)思路三:查找-->替换,其实只要remove @Override Annotation就可以 Ctrl+H to bring up the Search dialog Go to the "File Search" tab. Enter "@Override" in "Containing text" and "*.java" in "File name patterns". Click "Replace...", then "OK", to remove all instances of "@Override". |
相关文章推荐
- android学习—— Android导入源代码出现Remove @Override问题解决方法
- 关于android导入工程时出现的@Override错误问题的解决
- 导入Android工程源码出现乱码问题的解决方法
- 关于android导入工程时出现的@Override错误问题的解决<转>
- 关于android导入工程时出现的@Override错误问题的解决
- android项目导入到eclipse中去出现 Case Variant exsits问题的部分解决方法尝试
- 关于android导入工程时出现的@Override错误问题的解决(转)
- 适配Android 7.0出现读取外部存储问题解决方法
- android开发中遇到的问题解决之RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- Android eclipse导入项目后出现Unable to resolve target 'android-17'解决方法
- Android 出现Please ensure that adb is correctly located at问题的解决方法
- adb连接Android 4.2.2版本手机时出现offline或unauthorized问题的解决方法
- Android项目导入出现The type java.lang.Object cannot be resolved.问题解决办法!! .
- Android开发中调用系统相册上传图片到服务器OPPO等部分手机上出现短暂的显示桌面问题的解决方法
- Eclipse导入Android工程,出现default与Displaying的问题解决
- android导入项目@override编译错误解决方法
- Android Studio出现Failed to open zip file问题的解决方法
- 最近在ArcGIS Engine开发中关于调用gp工具过程出现COM 组件的调用返回了错误 HRESULT E_FAIL 错误的解决方法 和 学习oracle中遇到的一些问题总结
- 将Eclipse项目导入到Android studio 中 很多点9图出现问题解决方法
- Android学习过程中遇到的问题及解决方法