KWJ2104
KWJ2104

Reputation: 2009

Strange FileNotFoundException with Image

So I make a couple of images for my eclipse view plugin. Works perfectly. I wake up the next day and the program now tells me that it can no longer find those files. The files are definitely still in the same place I left them, and I haven't touched the code in 24 hrs. I've been messing with this for an hr now and I don't even know where the start debugging this, as my program was fine yesterday.

Sample.gif is in the "icons" folder of my plugin. I've tried moving it to the src folder, and that doesn't work either.

Error message:

org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: sample.gif (No such file or directory))

Code (when I remove this line and all lines of code that use testImage, the plugin runs again):

Image testImage = new Image(null, "sample.gif");

Anyone have any idea what could possibly be causing this, or what information i can provide for someone to give me a direction as to how to debug?

Upvotes: 1

Views: 1494

Answers (1)

Stephen C
Stephen C

Reputation: 719576

The problem is most likely to do with where the current directory is. When you use a pathname like "sample.gif", the normal behaviour when opening the file is to look in the current directory. If you run the application with a different current directory, the application will look for the file in a different place.


I'm however confused by the current directory concept

Here are some pages that describe the concept:

where should the pictures go?

If you are only ever going to run your application from within eclipse, then you can put them anywhere ... and make sure that your application's Eclipse launcher configuration sets the current directory to a consistent place. (Your current problem is most likely due to the application launcher using the parent Eclipse's current directory, and THAT may depend on where you were when you launched Eclipse ... see linked pages above.)

If you are going to export the built application in some form so that users can use it outside of Eclipse, then the answer depends on the nature of the application and how it will be installed on the user's computer. (On possible solution is to put the images into the application's JAR file, and locate them via the classpath using the ClassLoader.getResource methods.)

Upvotes: 1

Related Questions