Proper way to handle Android Studio's NullPointerException lint warning

后端 未结 8 2031
终归单人心
终归单人心 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:14

    I like the answer to this link.

    Warning is not an Error. And the warning which you are talking about says "it may produce", don't say 'it must produce'. So choice is yours. Either add null check or not

    So, If you are sure that findViewById in your code will never be cause of NPE, then don't add the null check.

提交回复
热议问题