It's caused because you create an array of size files.length
full of null
referecens.
With
File files[] = f.listFiles();
String[] theNamesOfFiles = new String[files.length];
You just create a new Array of length files.length
but don't add elements to it. So when the list try to create a view it just crash with NullPointerException
.
You can just edit the ArrayAdapter from <String> to <File> to avoid the creation of a new array, since ArrayAdapter will use .toString()
and File.toString()
returns the file path.
Or use .list()
to list every file and create an array of String[]
.