I created a small little java game and sent it to my friends but I realized that they don't have the images so they won't see the pictures that I put in the game. How would I make it able for them to view these images. Do I put them in the jar somehow? And what would I put for the path to these images?
Yes, put them in the Jar, often in their own directory, possibly off of the directory that holds the class files. You'll want to access them using resources not as files. The tutorials should show you the way.
How do I insert it into the jar? And what tutorials are you talking about? I'm sorry I feel so silly right now but it would be really cool if I could get this working!
I spoke too soon, I thought I had it but this code
I don't know why it doesn't work, the System.out.print prints out this
file:/PatricksFolder/java/Dodge!/Run1.jpg
Which appears correct but it won't run. Compiles fine but won't run.
Can I only run this when it is in the jar?
What happens when you try to run it? Any exceptions get triggered?
For my money, I'd try to create a small program that does nothing more than create an ImageIcon, places it in a JLabel, and shows the JLabel in a JOptionPane, and then make a Jar of it. If you can get this to work, you can get your main program to work, I'll bet.
If that's your real code I very much doubt so; you declare icon inside the if-statement, then try to access it afterwards when it's already out of scope.
And if it's not, PostRealCode.
Here is my entire code for the main class. If you need all the other classes I can post them. The error I get is a null pointer exception for this code
Weird huh?
EDIT: I set the private ImageIcon icon = new ImageIcon();
and I don't get the null pointer exceptions but now none of the images appear
It still prints out the correct file path and everything but no image appears
Is the Run1.jpg file located in the same folder (inside the JAR or not) as your Dodge.class file?
Oh, and change line 35 to "icon = ...". You are now declaring a new local variable that is instantiated in the if-block (if the resource is found). After that it goes out of scope (as I said) and the non-instantiated (and therefore null) icon instance field is used.
I am making a jar of the folder Dodge
Inside this folder are all the class files and another folder called images.
All my images are in this images folder.