Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By pbrockway2

Thread: Exporting to jar error

  1. #1
    Sean2012 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Exclamation Exporting to jar error

    Hi, i'm trying to export my eclipse project to a jar. I export it and everything is fine but when i go to run it i get this error.
    Java Code:
    C:\Documents and Settings\Administrator\Desktop>java -jar game.jar
    Running...
    Check Texures!
    Exception in thread "Thread-3" java.lang.ExceptionInInitializerError
            at com.war.warfare.graphics.Render3D.floor(Render3D.java:58)
            at com.war.warfare.graphics.Screen.render(Screen.java:27)
            at com.war.warfare.Display.render(Display.java:137)
            at com.war.warfare.Display.run(Display.java:107)
            at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: input
     == null!
            at com.war.warfare.graphics.Texture.loadBitmap(Texture.java:19)
            at com.war.warfare.graphics.Texture.<clinit>(Texture.java:8)
            ... 5 more
    Caused by: java.lang.IllegalArgumentException: input == null!
            at javax.imageio.ImageIO.read(Unknown Source)
            at com.war.warfare.graphics.Texture.loadBitmap(Texture.java:11)
            ... 6 more
    I'm new to java and can't find out what is wrong. I also uploaded my project files.
    Thanks for any help!

    game.zip

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Exporting to jar error

    Java Code:
    Caused by: java.lang.IllegalArgumentException: input == null!
            at javax.imageio.ImageIO.read(Unknown Source)
            at com.war.warfare.graphics.Texture.loadBitmap(Texture.java:11)
    Evidently the read() method was passed null in the statement on line 11 of Texture.java.

    Java Code:
    public static Render loadBitmap(String fileName) {
        try {
            BufferedImage image = ImageIO.read(Texture.class.getResource(fileName)); // <-- line 11
            int width = image.getWidth();
            int height = image.getHeight();
            Render result = new Render(width, height);
            image.getRGB(0, 0, width, height, result.pixels, 0, width);
            return result;
        } catch (Exception e) {
            System.out.println("Check Texures!");
            throw new RuntimeException(e);
        }
    }
    If you stop and think about it filename might have represented the name of a file on your harddisk somewhere, but that is no good now that your image textures are entries within a jar archive file.

    The thing to do is to use the form of the read() method that takes a URL argument. There is a method of the Class class - getResource() - that is useful in constructing this URL at runtime. Its use (and comparison with the similar CLassLoader method) is discussed in this JavaWorld article.

    As you move from file to URL based access of resources one gotcha (if you're on Windows) is with the case of the names. If you are trying to access "Floor.png" and your program happens to use the string "floor.png" then nothing will go wrong so long as you are dealing with files and Windows. But the moment you put things into a jar archive the rules change: names are case sensitive and the resource won't be found. A rule like always using lowercase for resources will help avoid this trap.
    2by4 likes this.

  3. #3
    Sean2012 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Exporting to jar error

    Yes, I eventually figured it out on my own, but thanks for the reply! I learned a lot from it! I'm new to all this and this is my first jar file. Thanks!

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Exporting to jar error

    Glad to hear you've figured it out. You're welcome, and good luck with the game.

Similar Threads

  1. Exporting to jar error
    By Sean2012 in forum Eclipse
    Replies: 0
    Last Post: 12-15-2011, 11:32 PM
  2. Exporting to JAR and running in cmd
    By JonnySnip3r in forum New To Java
    Replies: 2
    Last Post: 01-31-2010, 06:41 PM
  3. Problem when exporting to CSV
    By deepusrp in forum New To Java
    Replies: 10
    Last Post: 06-26-2009, 09:33 AM
  4. Greenfoot exporting in .jar?
    By sciguy77 in forum New To Java
    Replies: 0
    Last Post: 01-18-2009, 07:06 PM
  5. Exporting my project
    By Nim in forum CLDC and MIDP
    Replies: 3
    Last Post: 11-04-2008, 11:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •