4

I want to create

android @Nullable annotation

i check this two links for example

http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/Nullable.html http://code.google.com/p/google-guice/wiki/UseNullable

but none works in android because RetentionPolicy, ElementType is not valid

How can i create @Nullable annotation in android?

senzacionale
  • 20,448
  • 67
  • 204
  • 316

2 Answers2

2

Include jsr-305 jar file in project libraries. Use @nullable with fields and RoboGuice will stop complaining about null objects.

S.D.
  • 29,290
  • 3
  • 79
  • 130
2

For Android Studio:

  • Add the following to build.gradle:

    dependencies {
        ...
        // For @Nullable/@NonNull
        compile 'com.android.support:support-annotations:+'
    }
    
  • Go to File / SettingProject SettingsInspections and search for "nullable".

    In Constant conditions & exceptions and @NotNull/@Nullable problems, click Configure annotations and select Android's annotations.

    You may also want to check Suggest @Nullable annotations… under Constant conditions & exceptions, or possibly tweak other options.

squirrel
  • 5,114
  • 4
  • 31
  • 43