【问题标题】:Problem with Android Studio - error: cannot find symbol class RetentionAndroid Studio 出现问题 - 错误:找不到符号类保留
【发布时间】:2026-01-13 16:30:01
【问题描述】:

我的 Andoid Studio(3.5 版本)有问题。当我写一个类时,像这样:

public class ExampleEnum
{
    @Retention ( RetentionPolicy.SOURCE )
    @IntDef (
            {
                    A, B, C, D, E, F
            } )
    public @interface Numbers
    {
        int A = 0;
        int B = 1;
        int C = 2;
        int D = 3;
        int E = 4;
        int F = 5;
    }

如果我尝试运行我的应用程序,我总是会收到相同的错误:error: cannot find symbol class Retention anderror: cannot find symbol class IntDef

谁能帮助我?谢谢。

【问题讨论】:

  • 分享你的 gradle 文件。

标签: android android-studio


【解决方案1】:

您可能必须在 build.gradle 文件中包含以下内容:

dependencies {
    implementation 'com.android.support:support-annotations:28.0.0'
}

你的类中的导入语句是这样的:

import android.support.annotation.IntDef;
import java.lang.annotation.RetentionPolicy;

【讨论】:

  • 完成,没有变化。如果我在尝试运行我的应用程序时遇到其他代码错误,在我修复它之后我没有任何问题,我可以完美地运行我的应用程序。
  • 完成,同样的问题仍然存在。
  • intdef 和保留?
  • 是的,两者都是。如果我有四个像这个例子一样的类,我对这四个类有同样的错误。
最近更新 更多