我正在尝试在eclipse中运行示例android代码,但是当我尝试:
import android.annotation.SuppressLint;
我一直收到与此行相关的错误,如:
the import android.annotation cannot be resolved
如果有人能帮助我,我将不胜感激。
答案 0 :(得分:51)
你在项目中提到了哪些API。
由于
android.annotation.SuppressLint - 它是在API级别16中添加的
http://developer.android.com/reference/android/annotation/SuppressLint.html
你需要做下一步
您预设严格的鼠标点击 - >属性并查看下一张图片为您选择API级别的项目构建目标> = 16
答案 1 :(得分:19)
正如Artem建议的那样,您可能需要将annotations.jar文件包含在项目中,但请注意Android SDK中有两个annotations.jar文件:
android-sdk / tools / support / annotations.jar - 其中包括以下注释:
android-sdk / extras / android / support / annotations / annotations.jar - 其中包含许多其他注释:
答案 2 :(得分:12)
在android-sdk/tools/support/annotations.jar
中,它包含android.annotation.SuppressLint
和android.annotation.TargetApi's
定义。
答案 3 :(得分:2)
Dmitry Nelepov的回答是正确的,尽管有时您的项目已经在所需的项目构建目标上(这种情况发生在我的情况下)。只需将构建案例切换到另一个案例,按“确定”,然后重做步骤将其设置回正确的项目构建目标。