2013-02-14 58 views
32

我试图在Eclipse中运行的样本的Android代码,但是当我尝试:android.annotation解决不了

import android.annotation.SuppressLint; 

我不断收到有关这条线如下错误:

the import android.annotation cannot be resolved 

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

回答

49

你认为哪些API参考了你的项目。

因为

android.annotation.SuppressLint - 它,因为新增的API等级16

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

你需要做的下一

你的项目分辩鼠标单击 - >属性和下次检查图片为您选择API级别的项目构建目标> = 16

enter image description here

+0

谢谢,好像这就是问题所在。但是当我打开我的SDK管理器时,它不会给我任何升级到超过13的API级别的选项。我必须再次下载我的SDK吗? – m0j1 2013-02-14 09:28:53

+2

是的,你需要运行android sdk管理器chekout更新。之后,您必须运行Eclipse Update软件进行ADT插件更新。 – 2013-02-14 15:21:59

+0

导入库时也会出现此问题,例如Facebook SDK。由于某种原因,它被设置在比我的主要项目更低的层次上。我仅在libproject上出现错误,而不是我的主应用程序,并且必须更改构建路径才能使其工作。 – Rarw 2015-09-02 01:29:44

11

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

2

Dmitry Nelepov的回答是正确的,虽然有时候你的项目已经在期望的Project Build Target上(这发生在我的案例中)。只需将构建案例切换到另一个构建案例,按下“确定”,然后重做这些步骤将其重新设置回Project Project Target。

+0

也不管用。 – Josh 2016-07-14 21:33:34

15

由于阿尔乔姆建议,您可能需要包括annotations.jar文件到您的项目,但请注意,在你的Android SDK 2个annotations.jar文件:

Android的SDK /工具/支持/ annotations.jar - 包括以下注释:

  • SuppressLint
  • TargetApi

android-sdk/extras/android/support/annotations/annotations。罐子 - 其中包括许多其他注释:

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