I have many of these calls:
(ListView) getView().findViewById(R.id.main_list_view);
(TextView) getView().findViewById(R.id.items_no);
....
That is cause getView() may return null and is annotated as @Nullable, check out the sources and its JavaDoc - CTRL+Click on getView() call in your code.
/**
* Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
* if provided.
*
* @return The fragment's root view, or null if it has no layout.
*/
@Nullable
public View getView() {
return mView;
}
You can wrap your code yourself and check for null to have the warning go away, or otherwise place the cursor anywhere inside findViewById() call, wait couple of seconds for the lightbulb to show up (or press Alt+Enter) and then choose one of the suggested solutions.