I am trying to make my app read and show all the song files in it but whenever i am trying to run my app it keeps getting crashed. In my logcat 'java.lang.NullPointerException: Attempt to get length of null array' error keeps showing. And I know the problem is somewhere in the bellow code:
public ArrayList<File> findSong(File file){
ArrayList<File> arrayList= new ArrayList<>();
File[] files=file.listFiles();
for (File singleFile : files){
if(singleFile.isDirectory() && !singleFile.isHidden()){
arrayList.addAll(findSong(singleFile));
}
else {
if(singleFile.getName().endsWith(".mp3") || singleFile.getName().endsWith(".wav"));
{
arrayList.add(singleFile);
}
}
}
return arrayList;
}
Please help me .