android.annotation无法解析

m0j*_*0j1 36 java eclipse android

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

import android.annotation.SuppressLint;
Run Code Online (Sandbox Code Playgroud)

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

the import android.annotation cannot be resolved
Run Code Online (Sandbox Code Playgroud)

如果有人可以帮助我,我将不胜感激.

Dmi*_*pov 51

贵的API你在你的项目中提到过.

因为

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

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

你需要做下一步

您可以通过单击鼠标单击 - >属性并查看下一张图片,为API级别选择项目构建目标> = 16

在此输入图像描述

  • 是的,你需要运行android sdk manager来chekout更新.之后,您必须运行Eclipse Update软件以进行ADT插件更新. (2认同)

The*_*eIT 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


小智 12

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