I am trying to build an app with android studio. I am following a tutorial but the thing is, the guy paused the screen to start the emulator and when he played it again a piece of code was missing. I don't know for sure what he did but I tried all of the options presented to me.
I am getting this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
code:
public void onResponse(Call<Users> call, Response<Users> response) {
if (response.isSuccessful()) {
mediaObjectList = (ArrayList<MediaObject>) response.body().getAllPosts();
recyclerview.setMediaObjects(mediaObjectList);
VideoPlayerRecyclerAdapter adapter = new VideoPlayerRecyclerAdapter(mediaObjectList, initGlide());
recyclerview.setAdapter(adapter);
adapter.notifyDataSetChanged();
recyclerview.setKeepScreenOn(true);
recyclerview.smoothScrollToPosition(mediaObjectList.size()+1);
} else {
Toast.makeText(HomeActivity.this, "Network Error.", Toast.LENGTH_SHORT).show();
}
}
I'm getting the error on this line:
recyclerview.smoothScrollToPosition(mediaObjectList.size()+1);