Can't find @Nullable inside javax.annotation.*

2019-01-30 20:41发布

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

8条回答
Ridiculous、
2楼-- · 2019-01-30 21:06

If anyone has this issue when building a Maven project created in IntelliJ IDEA externally, I used the following dependency instead of the answer:

<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.

You can find it here.

查看更多
虎瘦雄心在
3楼-- · 2019-01-30 21:07

If you are using Gradle, you could include the dependency like this:

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'
}
查看更多
\"骚年 ilove
4楼-- · 2019-01-30 21:08

In the case of Android projects, you can fix this error by changing the project/module gradle file (build.gradle) as follows:

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

For more informations, please refer here.

查看更多
Viruses.
5楼-- · 2019-01-30 21:10

you can add latest version of this by adding following line inside your gradle.build.

implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
查看更多
够拽才男人
6楼-- · 2019-01-30 21:14

I am using Guava which has annotation included:

(Gradle code )

compile 'com.google.guava:guava:23.4-jre'
查看更多
该账号已被封号
7楼-- · 2019-01-30 21:19

You need to include a jar that this class exists in. You can find it here

If using Maven, you can add the following dependency declaration:

<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>jsr305</artifactId>
    <version>3.0.2</version>
</dependency>
查看更多
登录 后发表回答