A problem generating a jar file

Hello.

I have a project I’m working on for one of my classes. It’s a little pong game, nothing complicated. Actually, my game setup is very similar to the Arkanoids101 setup. Now here’s the problem. For my project I’m using NetBeans, I recreated the Arkanoids101 in the SDK and after I got it to work, I could run the .jar file for that project and it functioned just fine. Then I created my game, implemented the game setup and all the game logic, but when I try to run the .jar file created for it, the game window pops up for a second and disappears. Nothing else happens. Any ideas?

How are you running the Jar file? If you arent running it from teh command line, do so and look at the output.

Well i was just double clicking the file :open_mouth: I ran the file from the command file, but i simply went to the directory and did: arkanoids.jar. The same thing happened and nothing printed in the prompt >< Should I run it from command line using the java application command or something? Sorry for the noobness QQ And thanks for the help :smiley:

Go to your directory (in command prompt). Than type


java -jar  arkanoids.jar

and you should be able so see some output, as Jeff suggested…

Alright, I got some out put now. I keep all my gif’s in my project in a folder called sprites, so when I load an image for an object , say : Entity brick = new BrickEntity(this,“sprites/brick.gif”,100+(x50),(50)+row35); Now when I run the jar file from the command prompt I get this message: can’t find ref: sprites/ball.gif. I tried puting the jar file in the same directory as the sprites forlder but that didn’t help :frowning: Any ideas?

BufferedImage i;
[…]
try {
i=ImageIO.read(new BufferedInputStream(getClass().getResourceAsStream("/tex/foo.png")));
}catch(IOException e){
e.printStackTrace();
}

The ‘/’ at the beginning ensures that it searches from the “root” of the classpath (its kinda absolute). This means that it doesnt matter where you are currently in the hirachy… the resource will always be found.

The BufferedInputStream bit is a workaround for some imageio bug.

If getClass() doesnt work (static context) write the full class name (eg FooBar.class) instead.

This approach always works… jar-ed or not.

Check this out, oNyx, I tried to use the code that you posted and that’s what i ended up with:
public Sprite getSprite(String ref) {

// if we've already got the sprite in the cache
// then just return the existing version
if (sprites.get(ref) != null) {
	return (Sprite) sprites.get(ref);
}
            
            BufferedImage sourceImage = null;
            try {
            sourceImage=ImageIO.read(new BufferedInputStream(getClass().getResourceAsStream(ref)));
            if(sourceImage == null)
            {
                fail("Can't find ref: "+ref);
            }
            }catch(IOException e){
            e.printStackTrace();
            }
			
// create an accelerated image of the right size to store our sprite in
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
Image image = gc.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.BITMASK);
	
// draw our source image into the accelerated image
image.getGraphics().drawImage(sourceImage,0,0,null);
	
// create a sprite, add it the cache then return it
Sprite sprite = new Sprite(image);
sprites.put(ref,sprite);
	
return sprite;

}

The parameter ref that comes in to the function is for example “/sprites/ball.gif”
I tried to run the jar file with this and the code still breaks at the fail in this function and I still get this message: Can’t find ref: /sprites/ball.gif
Am I doing something wrong again? >< thx for all the help. :slight_smile:

Does any jar in the classpath contain a directory called “sprites” with “ball.gif” in it?

Or is there a directory called “sprites” (with “ball.gif” in it) in the directory you’re starting your application from?

I put a folder named sprites with all the pictures in it in the same directory as the jar file

Oh my god, i am a frikking idiot!!! QQ
Wow, i really hate myself right now :*(

So… When I created all the sprites for my game, I made them in paint, and guess what format it saved them in? .GIF !!!
I just spent an entire day thinking I was getting some crazy error and it turns out that all my files were .GIF’s instead of .gif’s.
Wow.

But anyway, thanks for all your help fellas, you are awesome! Keep it up!!!

Catch ya later :smiley:

Oh yea… always use lowercase extensions. I have the feeling that microsoft did that on purpose… Afaict paint is the only program which tends to use uppercase file extensions.