This piece of code work on my ubuntu box, when I import it onto Eclipse on my window, it complains:
This is the line that it complains
fileImg return null after this line, mean either directory is not exist or there is some IO error. So I print out the path of "dir" which is the folder "image" in the same directory as my source code, and I get a valid path. So the directory do exist. "dir" reference the directory. So what could be the problem? Here is my code
Well, the API documentation has this to say about the listFiles method:
Returns null if this abstract pathname does not denote a directory
So that's what is happening. I suspect you are making some assumptions about that so-called directory which aren't correct.
Joined: Jan 21, 2009
Sorry, it was a stupid mistake, i have the folder in the wrong location. I have the source file and image folder inside src folder, you know I want them to be in the same level. However, Eclipse does not think current level is where the source file is, to Eclipse, current level is the same level as src folder, where the project file is. That why it could not see the "image folder"
Yes... if you hadn't mentioned that you were a Unix user, I would have mentioned the possibility of differences in the current working directory. But Unix users generally know that concept. Anyway, you got it fixed so that's the main thing.
subject: Cant load files into array using listFiles. I think it's an eclipse problem