I am running java code using Netbeans IDE in Ubuntu 12.04.
I am trying to create a file object with a pathname to a file directory and using the method listFiles() to return an array of pathnames under this file directory.
The code:
File allFile=new File("~/Desktop/matlab/CAT_00");
File[] fileList = allFile.listFiles();
However when i ran the the code, i get an exception declaring
Exception in thread "main" java.lang.NullPointerException
at CatTest.main(CatTest.java:29)
Java Result: 1
So it appears that either my allFile object contains null object? I am not really sure myself. I tried checking the directory path that i wanted which was "~/Desktop/matlab/CAT_00" and it was correct. I tried using the debugging mode to check these 2 lines of code and found that listFiles() returned this exception error. However i do not understand why there should be an null exception error since there was files and directories under the CAT_00 main directory i created the File object with in the 1st place and hence should have returned an array of pathnames for these files and directories instead.
Help is much appreciated!!
File allFile=new File("~/Desktop/matlab/CAT_00"); ..to immediately print outallFile.exists()&allFile.isDirectory().