• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting picture into netbeans

 
Manik Jay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to develop a small game with netbeans.I wanted to load a picture into my game.I placed the picture in the directory where the jar file was and gave the full url to that picture But when I run the game there is an exception because the image didn't load.I want to know where i should place the image
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the code you are using to load the image and the exception. Then we can help you. At this point, we would be guessing. And I left my crystal ball at home.
 
Kayvon Farvardin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luckily I brought my crystal ball with me.

Now I'm not even sure if this is right since I am noob... but I don't think you enter the full directory path for the photo at all. You just do blah.blahBlah(mypicture.jpg) or somthing similar. Not C:/Program Files/NetBeans/Projects/MyUberGame/mypicture.jpg

If thats correct, this will be the first time I helped answer somones Java question before. *crosses fingers*
[ October 21, 2006: Message edited by: Kavon Farvardin ]
 
Manik Jay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kavon Farvardin:
[

you enter the full directory path for the photo at all. You just do blah.blahBlah(mypicture.jpg) or somthing similar. Not C:/Program Files/NetBeans/Projects/MyUberGame/mypicture.jpg

Kavon Thanks for the help
but I tried both ways.first I typed
the full path name like C:/My Documents/mypicture.jpg then when it didn't work I copied the picture to the "src" directory of my project folder and typed in the full path to that location then again tried with just the name of the picture....but in the end nothing worked

[ October 31, 2006: Message edited by: Manik Jay ]
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do not access resources (pictures, config files ...) with full file p´┐Żath. Use a resource path instead. Put the resource on the class path (i.e. configure your IDE to have a directory "resources" on the class path) and the store all your pictures in this directory.

- resources/picture/a.jpg
- resources/picture/b.gif
- resources/config/myIniFile.bla

then get the URL/input stream for this resource trough the class loader:

then something like this should do the trick

(or getResource() or the methods found in java.lang.Class (depending on Java version)

like this you do not need to change your program if you deploy it on another machine and you also do not mandate a specific file path. Or if you consider deploying using webstart or ....


pascal
 
Paulo Pontes
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only complementing Pascal...


I couldn't use "/" and had to use "\\" for a correct behavior under windows. is it the same at other platforms?
 
Manik Jay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys but 1 last question.how do you configr netbeans to have a "resources" directory.
 
Paulo Pontes
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the easyest way is creating the directory as a java package, just dont put any class, just resource files. This way the make and run script will put the files where it belongs
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic