Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Where do I put my image files in Eclipse?(My GUI loads, but the images i want to load are not on it. . .)
Where do I put my image files in Eclipse? [message #696479] Thu, 14 July 2011 05:05 Go to next message
goldminer91g is currently offline goldminer91gFriend
Messages: 4
Registered: July 2011
Junior Member
I am a self-taught programmer, still in high school, so im a bit under educated with java, but im working on it.

I say this because I believe my problem is an easy fix, and its just something im not entirely sure on. I am making a program that uses ImageIcons. I encapped the whole process of getting the ImageIcons in a try/catch, and as far as I can tell, the Images SHOULD be loaded. But, when I run my GUI, the images are missing.

And so my question for you guys is this: where do my images need to be on my computer? They are currently here:

C:\Documents and Settings\Max\workspace\Project_One\src\Game_Images
(I run a windows XP).

I currently have my images in a folder that is with my code's files, in the src folder. Is this the correct place to put the images?



This problem is very odd to me, because like i said, I am not getting any errors from the compiler or my catch statements. Any Idea as to what might be going on?
Re: Where do I put my image files in Eclipse? [message #696680 is a reply to message #696479] Thu, 14 July 2011 15:10 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
You don't specify how you are trying to access the images. This is an important piece of information in determining where they need to be placed. The recommended approach would be to load them as resources through the class loader. You then need to follow the rules for accessing resources specified in the getResource methods on the Class object. If you are trying to access them using the File class, you probably want to specify relative path names. In that case, you need to place them relative to some known runtime location such as the working directory for your launch. In Eclipse you can find the working directory for a given launch on the Arguments tab of the Launch Configuration.

Your question is really more of a general Java development question. These forums are for questions about using the Eclipse tools not for general Java development questions. You may want to look to more general Java forums on sites like stack overflow or Java ranch.
Re: Where do I put my image files in Eclipse? [message #696742 is a reply to message #696680] Thu, 14 July 2011 18:35 Go to previous messageGo to next message
goldminer91g is currently offline goldminer91gFriend
Messages: 4
Registered: July 2011
Junior Member
This forum says Java Development Tools: that to me says that this forum is about learning to use tools of the compiler: in this case, the compiler of Eclipse. For the development of my program, i need to be able to load images, which i am doing by creating ImageIcons, which use a path to find the desired images. I made a new folder in my project, put my images in there, and still, when I run my program, the spots where the images should be are empty, but there are no returned errors. Here is an example of that code:

try{
Icon Full_HP = new ImageIcon("Project_One/src/Images/Game_Images/Wood_fullHP.jpg");

}catch(Exception FileLoadException){
System.out.println("Failed to load Wood_Block ImageIcon.")
}
Re: Where do I put my image files in Eclipse? [message #696793 is a reply to message #696742] Thu, 14 July 2011 20:29 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
This isn't a question about learning the compiler, it is a question about learning Java and isn't appropriate for this forum.

In order for the ImageIcon to load the correct file, you have to run your application in the directory that contains Project_One.

Previous Topic:Tomcat not using project build path (Indigo)
Next Topic:Binding not resolved => ClassPath Problem ?
Goto Forum:
  


Current Time: Wed Apr 24 17:12:17 GMT 2024

Powered by FUDForum. Page generated in 0.02998 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top