android.annotation无法解析

时间:2013-02-14 08:27:44

标签: java android eclipse

我正在尝试在eclipse中运行示例android代码,但是当我尝试:

import android.annotation.SuppressLint;

我一直收到与此行相关的错误,如:

the import android.annotation cannot be resolved

如果有人能帮助我,我将不胜感激。

4 个答案:

答案 0 :(得分:51)

你在项目中提到了哪些API。

由于

android.annotation.SuppressLint - 它是在API级别16中添加的

http://developer.android.com/reference/android/annotation/SuppressLint.html

你需要做下一步

您预设严格的鼠标点击 - >属性并查看下一张图片为您选择API级别的项目构建目标> = 16

enter image description here

答案 1 :(得分:19)

正如Artem建议的那样,您可能需要将annotations.jar文件包含在项目中,但请注意Android SDK中有两个annotations.jar文件:

android-sdk / tools / support / annotations.jar - 其中包括以下注释:

  • SuppressLint
  • TargetApi

android-sdk / extras / android / support / annotations / annotations.jar - 其中包含许多其他注释:

  • AnimRes
  • AnimatorRes
  • AnyRes
  • ArrayRes
  • AttrRes
  • BoolRes
  • ColorRes
  • DimenRes
  • DrawableRes
  • FractionRes
  • IdRes
  • IntDef
  • IntegerRes
  • InterpolatorRes
  • LayoutRes
  • MenuRes
  • 非空
  • 可空
  • PluralsRes
  • RawRes
  • StringDef
  • StringRes
  • StyleRes
  • StyleableRes
  • XmlRes

答案 2 :(得分:12)

android-sdk/tools/support/annotations.jar中,它包含android.annotation.SuppressLintandroid.annotation.TargetApi's定义。

答案 3 :(得分:2)

Dmitry Nelepov的回答是正确的,尽管有时您的项目已经在所需的项目构建目标上(这种情况发生在我的情况下)。只需将构建案例切换到另一个案例,按“确定”,然后重做步骤将其设置回正确的项目构建目标。