5 Replies Latest reply: Apr 1, 2010 5:59 PM by 843853 RSS

    Jar file doesn't run properly, please help!

    843853
      Hi everyone, i'm a student and i'm programming a game for my homework of AI subject. When i compiled the code from Eclipse, the game run smoothly, but when I create the jar file of the project, it appear blank when i run it. Here is the image:
      [blank screen|http://c.upanh.com/upload/4/299/3L0.8429518_1_1.png]
      and run from Eclipse:
      [Run from Eclipse|http://c.upanh.com/upload/4/299/TL0.8429668_1_1.png]
      I have followed the instruction of creating jar file in Eclipse properly, and now the trouble come. If anyone can show me how to solve this problem?
      Thanks all.
        • 1. Re: Jar file doesn't run properly, please help!
          843853
          I'm guessing, since you don't include any code, that you're probably missing--not finding--some of your resources--like the screen image file. Do you have try/catch blocks that look like this (notice the empty catch block):
          try{
          //code for what ever
          }catch(Exception e){
          }
          If you do, then go back and change them to this:
          try{
          //code for what ever
          }catch(Exception e){
            System.out.println(e.toString);
          }
          or this:
          try{
          //code for what ever
          }catch(Exception e){
            e.printStackTrace();
          }
          And your code will tell you what is wrong.
          • 2. Re: Jar file doesn't run properly, please help!
            843853
            I have all of e.printStackTrack( ) in my try - catch block. But i also think the blank screen appears because the class can not find my resources. Maybe it's my fault, because i create by hand a folder name "res" in project folder, then put all my resource in this folder. And in Eclipse when i try to get these resource, i wrote something like this:
                 Image robot1N, robot1E, robot1S, robot1W;
                 private void initResources() {               
                      try {               
                           String sb = "car1";
                           robot1N = ImageIO.read(new File("res\\img\\unit\\" + sb +"_N.png"));
                           robot1E = ImageIO.read(new File("res\\img\\unit\\" + sb +"_E.png"));
                           robot1S = ImageIO.read(new File("res\\img\\unit\\" + sb +"_S.png"));
                           robot1W = ImageIO.read(new File("res\\img\\unit\\" + sb +"_W.png"));
                      }
                      catch(Exception e) {
                           e.printStackTrace();
                      }
                 }
            Maybe the string of path to resource is right in Eclipse but wrong in Window?
            • 3. Re: Jar file doesn't run properly, please help!
              843853
              When you get into the JAR file, you need to use getResource. You should be getting some error report someplace saying that the resource cannot be found.
              • 4. Re: Jar file doesn't run properly, please help!
                gimbal2
                I believe ImageIO.read() just returns null if it cannot find the file (the javadoc seems to agree there), so you don't get an exception.

                It will complain when it gets passed a null-value parameter, so passing the result of getResource() or getResourceAsStream() to it will result in an (IllegalState) exception when the resource could not be found.
                • 5. Re: Jar file doesn't run properly, please help!
                  843853
                  I still cannot create the jar file which run properly. So here i upload my project of Eclipse so if anyone can found out a way to solve this problem, please show me!
                  [Eclipse Project|http://www.mediafire.com/?qyij4xn2zy5]