So I'm trying to program a mediafile scanner that can give me the extension, quality and mediatype(movie,tvshow -> online database search)
of files. Now everything works. I can recursively search through my whole external harddisk without a problem. It retrieves all files and does everything I want it to.
However when I try to scan the c:/ I think I run in to a permission problem because it throws a nullpointer exception while it does receive the files.
This is my recursion alghorithm:
Here's what I've tried so farpublic void getFiles(File file) { //put files in list if (file.isDirectory() && (!file.isHidden())) { File[] folder = file.listFiles(); recurse(folder); } else { listOfFiles.add(file); } } public void recurse(File[] file) { //recursive search method for (File f : file) { if (f.isDirectory()) { recurse(f.listFiles()); } else { listOfFiles.add(f); } } }
Anyone know why it's failing?public void getFiles(File file) { //put files in list if (file.isDirectory() && (!file.isHidden()) && file.canRead() && file.canWrite() && file.canExecute()) { File[] folder = file.listFiles(); recurse(folder); } else { listOfFiles.add(file); } } public void recurse(File[] file) { //recursive search method for (File f : file) { if (f.isDirectory()) { recurse(f.listFiles()); } else { listOfFiles.add(f); } } }
full stacktrace
Exception in thread "main" java.lang.NullPointerException at VidScan.Model.VideoLibrary.recurse(VideoLibrary.java:37) at VidScan.Model.VideoLibrary.getFiles(VideoLibrary.java:30) at VidScan.View.Console.Console.<init>(Console.java:13) at VidScan.StartApp.main(StartApp.java:6) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)