I am trying to add a list of audio files to my fragment. I have also set the layout manager to recycler view. I have also added dependencies to gradle build
Here is the error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View androidx.recyclerview.widget.RecyclerView.findViewById(int)' on a null object reference
at com.example.musicplayer.AllSongs.onCreateView(AllSongs.java:35)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
I am trying to get all songs in my all songs fragment. Here is my code which shows error:
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
recyclerView = recyclerView.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
if (!(musicFiles.size() < 1))
{
musicAdapter = new MusicAdapter(getContext(),musicFiles);
recyclerView.setAdapter(musicAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
return inflater.inflate(R.layout.fragment_all_songs_tab, container, false);
}