Answer the question
In order to leave comments, you need to log in
How to fix recycler view not using data error?
Created a recycler view with GridLayoutManager however it doesn't want to read data from prepareGalleryData()
. Gives an error message
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference
at com.example.asus.testapp147.UserProfile_PhotoFragment.prepareGalleryData(UserProfile_PhotoFragment.java:58)
galleryList.add(gallery);
) inGalleryGridObject gallery = new GalleryGridObject(R.drawable.city);
galleryList.add(gallery);
prepareGalleryData()
private void prepareGalleryData()
{
GalleryGridObject gallery = new GalleryGridObject(R.drawable.city);
galleryList.add(gallery);
gallery = new GalleryGridObject(R.drawable.city);
galleryList.add(gallery);
gallery = new GalleryGridObject(R.drawable.city);
galleryList.add(gallery);
mAdapter.notifyDataSetChanged();
}
onCreateView
fragment prepareGalleryData();
Answer the question
In order to leave comments, you need to log in
The galleryList field is not initialized anywhere, i.e. is always null.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question