在 javax.annotation.* 中找不到 @Nullable
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19030954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't find @Nullable inside javax.annotation.*
提问by
I want use @Nullable
annotation to eliminate NullPointerExceptions
.
I found some tutorials on the net, I noticed that this annotation comes from the package javax.annotation.Nullable
;
but when I import it a compilation error is generated: cannot find symbol
我想使用@Nullable
注释来消除NullPointerExceptions
. 我在网上找了一些教程,我注意到这个注释来自于包javax.annotation.Nullable
;但是当我导入它时会生成一个编译错误:找不到符号
采纳答案by david99world
You need to include a jar that this class exists in. You can find it here
您需要包含一个存在此类的 jar。您可以在此处找到它
If using Maven, you can add the following dependency declaration:
如果使用 Maven,则可以添加以下依赖项声明:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
and for Gradle:
对于 Gradle:
dependencies {
testImplementation 'com.google.code.findbugs:jsr305:3.0.2'
}
回答by jan
The artifact has been moved from net.sourceforge.findbugs
to
神器已经从移动net.sourceforge.findbugs
到
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.0</version>
</dependency>
回答by mkobit
If you are using Gradle, you could include the dependency like this:
如果您使用的是 Gradle,则可以像这样包含依赖项:
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'
}
回答by Janis Peisenieks
In case someone has this while trying to compile an Android project, there is an alternative Nullable implementation in android.support.annotation.Nullable
. So take care which package you've referenced in your import
s.
如果有人在尝试编译 Android 项目时遇到这种情况,android.support.annotation.Nullable
. 因此,请注意您在import
s 中引用了哪个包。
回答by John Tribe
I am using Guava which has annotation included:
我正在使用包含注释的番石榴:
(Gradle code )
(毕业代码)
compile 'com.google.guava:guava:23.4-jre'
回答by crawton
If anyone has this issue when building a Maven project created in IntelliJ IDEA externally, I used the following dependency instead of the answer:
如果有人在外部构建在 IntelliJ IDEA 中创建的 Maven 项目时遇到此问题,我使用以下依赖项而不是答案:
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>15.0</version>
</dependency>
Using this will allow the project to build on IntelliJ IDEA and by itself using Maven.
使用这将允许项目在 IntelliJ IDEA 上构建,并使用 Maven 本身。
You can find it here.
你可以在这里找到它。
回答by KPandian
In the case of Android projects, you can fix this error by changing the project/module gradle file (build.gradle) as follows:
对于 Android 项目,您可以通过更改项目/模块 gradle 文件 (build.gradle) 来修复此错误,如下所示:
dependencies { implementation 'com.android.support:support-annotations:24.2.0' }
For more informations, please refer here.
有关更多信息,请参阅此处。
回答by Jay Dangar
you can add latest version of this by adding following line inside your gradle.build.
您可以通过在 gradle.build 中添加以下行来添加最新版本。
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'