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
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.
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
Joined: Jul 25, 2006
Posts: 4
posted
0
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
Joined: Jun 19, 2001
Posts: 547
posted
0
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.
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
Joined: Dec 06, 2004
Posts: 20
posted
0
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
Joined: Jul 25, 2006
Posts: 4
posted
0
Thanks a lot guys but 1 last question.how do you configr netbeans to have a "resources" directory.
Paulo Pontes
Greenhorn
Joined: Dec 06, 2004
Posts: 20
posted
0
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