gpt4 book ai didi

java - 导入 NotNull 或 Nullable 并且 Android Studio 不会编译

转载 作者:IT老高 更新时间:2023-10-28 20:26:23 25 4
gpt4 key购买 nike

当我向参数添加 @NotNull 或 @Nullable 注释时,Android Studio 会自动帮助我添加/lib/annotations.jar 和导入

import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable;

但在此之后,项目将无法编译。如果我也删除注释但保留导入语句,项目仍然无法编译。 但是如果我删除 NotNull 和 Nullable 的导入语句,项目编译很好!

Android Studio 给出一般错误:

Gradle: 
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

从 cmd 运行 gradlew compileDebug 会给出一点提示:

:Bugtester:compileDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

所以我检查了我的环境变量,它们设置为:

JAVA_HOME=C:\Program Files (x86)\Java\jre7
JDK_HOME=C:\Program Files\Java\jdk1.7.0_21\

有人对此有任何想法吗? (我是 java 和 android 编程新手)

最佳答案

我想,正确的方法是在 build.gradle 依赖项中使用来自 MavenCentral 存储库的原始 JetBrains 库(本示例中为最新可用版本):

dependencies {
implementation 'com.intellij:annotations:+@jar'
...
}

关于java - 导入 NotNull 或 Nullable 并且 Android Studio 不会编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16690914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com