【问题标题】:How to resolve error cannot find symbol class for Retention and IntDef?如何解决错误找不到 Retention 和 IntDef 的符号类?
【发布时间】:2018-09-01 04:35:33
【问题描述】:

我想要一个只接受 2 个值的函数,比如 onetwo。我可以使用枚举,但对于 Android,使用常量 (@IntRef) 被认为更好。

所以我这样做了:

@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_ONE, TYPE_TWO})
public @interface InputTypes {
    int TYPE_ONE = 0;
    int TYPE_TWO = 1;
}

但在构建 APK 时出现以下错误:

错误:找不到符号类保留
错误:找不到符号类 IntDef`

附:我尝试清理项目,多次使缓存无效。 (还添加了导入语句)

Android Studio 版本:3.0.0
minSdkVersion = 11
targetSdkVersion = 25
compileSdkVersion = 25
buildToolsVersion = '24.0.2'

编辑:

Java 版本:8

【问题讨论】:

  • 你导入java.lang.annotation.Retentionjava.lang.annotation.RetentionPolicy了吗?
  • @ChrisGong 是的,我做到了。
  • 正在使用 java 8 吗?

标签: java android android-studio


【解决方案1】:

SuppressLint 是在 API 级别 16 中添加的,因此您需要升级到 API 级别 16。
另一种解决方案是将appcompat-v7 添加到您的项目build.gradle,如下所示:

dependencies {
    ...
    implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
    ...

【讨论】:

    猜你喜欢
    • 2019-11-01
    • 2018-08-16
    • 2013-01-15
    • 2021-10-09
    • 2011-09-14
    • 2020-10-21
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    相关资源
    最近更新 更多