• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Cant load files into array using listFiles. I think it's an eclipse problem

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28291
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Thang Pham
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
 
Paul Clapham
Marshal
Posts: 28291
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic