loremaster
January 11th, 2013, 05:02 AM
Hi guys,
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. So i can't really figure out what can be wrong here?
Edit:
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 appreciated! Thank you!
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. So i can't really figure out what can be wrong here?
Edit:
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 appreciated! Thank you!