Skip to content Skip to sidebar Skip to footer

Fragment: Attempt To Invoke Virtual Method 'android.view.view Android.view.view.findviewbyid(int)' On A Null Object Reference

I am trying to insert a GridView which is populated from my SQLite Database, but I am getting the error 'Attempt to invoke virtual method 'android.view.View android.view.View.find

Solution 1:

Problem is getView() returns null.

in fragment you have to use: fragment's view instance.

so instead of:

gridView = (GridView) getView().findViewById(R.id.gv_players);

use:

gridView = (GridView) view.findViewById(R.id.gv_players);

Post a Comment for "Fragment: Attempt To Invoke Virtual Method 'android.view.view Android.view.view.findviewbyid(int)' On A Null Object Reference"