Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A problem generating a jar file  (Read 1297 times)
0 Members and 1 Guest are viewing this topic.
Offline smellyfish

Junior Newbie





« Posted 2005-11-17 00:10:15 »

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?
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-11-17 00:18:41 »

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

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline smellyfish

Junior Newbie





« Reply #2 - Posted 2005-11-17 03:06:41 »

Well i was just double clicking the file :O  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 Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hvor2

Junior Member




Beyond mind, there is an awareness...


« Reply #3 - Posted 2005-11-17 08:16:59 »

Go to your directory (in command prompt). Than type
1  
java -jar  arkanoids.jar

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

Offline smellyfish

Junior Newbie





« Reply #4 - Posted 2005-11-18 00:02:05 »

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+(x*50),(50)+row*35);  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 Sad  Any ideas?
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #5 - Posted 2005-11-18 00:17:34 »

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.

弾幕 ☆ @mahonnaiseblog
Offline smellyfish

Junior Newbie





« Reply #6 - Posted 2005-11-18 01:05:06 »

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. Smiley
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #7 - Posted 2005-11-18 02:36:40 »

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?

弾幕 ☆ @mahonnaiseblog
Offline smellyfish

Junior Newbie





« Reply #8 - Posted 2005-11-18 03:00:49 »

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

Junior Newbie





« Reply #9 - Posted 2005-11-18 04:25:48 »

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 Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #10 - Posted 2005-11-18 05:22:24 »

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.

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (36 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (41 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (35 views)
2014-09-21 00:26:15

UprightPath (48 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!