When inflating an element with findViewById
, Android Studio always warns me that my inflated view may return null
View v = inflater.inflate(R.layout.fragment_photo_gallery, container, false);
and suggests I do something like surround with my statement with a null check:
if (v != null) {
mGridView = (GridView)v.findViewById(R.id.gridView);
}
Is it recommended to always do the mentioned null check before inflating an element?
EDIT: Adding lint pictures