Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Where should images be placed  RSS feed

 
J R Hatch
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using the method

javax.swing.ImageIcon(getClass().getResource("/resources/tile00.png"))

where should tile00.png be located in directory structure? I had it in a directory under the package directory called resources. Is that not where it should go? If it matters I'm using ubuntu and am invoking javac from a directory called "programming" on an external hard drive.
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be in a directory named "resources" which is a subdirectory of one of the directories in your classpath.

You didn't tell us anything about your classpath, which was unfortunate because it's the classpath which controls where the classloader looks for resources like that.
 
J R Hatch
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:It should be in a directory named "resources" which is a subdirectory of one of the directories in your classpath.

You didn't tell us anything about your classpath, which was unfortunate because it's the classpath which controls where the classloader looks for resources like that.


I haven't actually set my classpath, so it should be the default, which is the directory that I invoke the javac command from, right?

So I went to try to move the .png file to the right place and found I hadn't even put it where I thought it went. This was not a lack of java understanding. The error existed between keyboard and chair.
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To put it more precisely: if you don't declare a classpath, then the current working directory is used as the classpath.
 
J R Hatch
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:To put it more precisely: if you don't declare a classpath, then the current working directory is used as the classpath.


Yeah. I thought I misunderstood, but actually I had just not put the files where I (correctly) thought they should go.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!