Proper way to handle Android Studio's NullPointerException lint warning

后端 未结 8 1924
终归单人心
终归单人心 2020-12-16 09:41

I\'m new to android/java programming and am confused how to properly deal with this warning.

Method invocation \'\' may produce \'Java.lang.NullPointe

相关标签:
8条回答
  • 2020-12-16 10:18

    I started to use

    @SuppressWarnings("ConstantConditions")

    on simple methods where I'm sure that the id is not null.

    0 讨论(0)
  • 2020-12-16 10:24

    I personally prefer using try{ }catch{ } simply because it is more elegant. However, it does add a lot of bulk to your code, if you imagine putting every, possible, NULL value into a try catch (if they are not next to each other)

    0 讨论(0)
提交回复
热议问题