Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Illegal Argument Exception: input == null

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Illegal Argument Exception: input == null

    So, I'm creating a card game. To create the background image I create a level class from a bunch of different tiles. These tiles are selected from scanning a .png image: depending on the colors of the pixels of the image, the level tiles are selected.

    I'm developing this in Eclipse, and running it from there has never been a problem.

    However, when I tried exporting it as a runnable jar I couldn't start it by clicking it. So, I tried running it through windows command prompt instead. My program didn't run now either, but I got the following readout in the command prompt:

    D:\The Documents\Programmering\Project\ProjectAI>java -jar ProjectAI1.jar
    Exception in thread "main" java.lang.IllegalArgumentException: input == null!
            at javax.imageio.ImageIO.read(Unknown Source)
            at org.geec.bluffai.level.Level.loadLevel(Level.java:40)
            at org.geec.bluffai.level.Level.<init>(Level.java:26)
            at org.geec.bluffai.graphics.Screen.<init>(Screen.java:23)
            at org.geec.bluffai.Coordinator.<init>(Coordinator.java:35)
            at org.geec.bluffai.Starter.main(Starter.java:10)

    I then went to check my loadLevel method and it looked like this: [Java] Loadlevel first - Pastebin.com (Note that I do not know really anything about the try-catch block or exception-throwing in general.)

    I did some google searches and changed my catch statement to

    catch (IllegalArgumentException | IOException e)

    so that my loadLevel method now looks like: [Java] Loadlevel second - Pastebin.com

    I then exported it as a new executable jar and ran it again. This time it started. However, when using the command prompt to run it I got these readouts:

    D:\The Documents\Programmering\Project\ProjectAI>java -jar ProjectAI2.jar
    [ERROR] Can't load level.
    java.lang.IllegalArgumentException: input == null!
            at javax.imageio.ImageIO.read(Unknown Source)
            at org.geec.bluffai.level.Level.loadLevel(Level.java:40)
            at org.geec.bluffai.level.Level.<init>(Level.java:26)
            at org.geec.bluffai.graphics.Screen.<init>(Screen.java:23)
            at org.geec.bluffai.Coordinator.<init>(Coordinator.java:35)
            at org.geec.bluffai.Starter.main(Starter.java:10)
    [ERROR] Can't load level.
    java.lang.IllegalArgumentException: input == null!
            at javax.imageio.ImageIO.read(Unknown Source)
            at org.geec.bluffai.level.Level.loadLevel(Level.java:40)
            at org.geec.bluffai.level.Level.<init>(Level.java:26)
            at org.geec.bluffai.graphics.Screen.<init>(Screen.java:23)
            at org.geec.bluffai.Coordinator.start(Coordinator.java:43)
            at org.geec.bluffai.Starter.main(Starter.java:12)

    While the game is now runnable, the problem is still there. I would want to fix this but I do not know how to, as I do not know why I'm receiving these errors while running the game as an executable, but not while running it in Eclipse. As such I wonder if anyone have any idea of what the cause could be or how I could fix it?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Illegal Argument Exception: input == null

    For better help sooner, I recommend creating an SSCCE that demonstrates exactly what you're trying to do without any extra code. For your purposes, a main method that uses ImageIO to read in an image and print out its width would suffice.

    But without seeing the SSCCE, I would guess that the path you're passing into the ImageIO is no longer valid when you export the jar.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Illegal Argument Exception: input == null

    The weird thing is that the .jar does work after I added the extra "catch" part after the ImageIO.read() so while it does indeed seem like my path would not be valid when I've exported the jar, it must be, as the proper image is read in, it just throws an exception first.

    I've been trimming away code to create an SSCCE for a bit now, however I have yet to create anything that would make sense as an SSCCE without actually creating a new program from scratch (I could do that but then everything works flawlessly). Hopefully I can get something up soon though.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Illegal Argument Exception: input == null

    Yeah, the typical way to create an SSCCE is to start from scratch and only add the offending line. If that works, then you know your actual problem starts on a different line.

    The only thing adding a catch block will do is, well, catch the exception. Unless that exception was expected, you're probably just covering up your actual problem.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Illegal Argument Exception: input == null

    Is the image you are attempting to read located inside of your jar? If so, that would be one of several problems. The files in jars are in a compressed format. You must access resources in jars as Streams instead of attempting to directly access them with a path like you would a normal file.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. illegal state exception from regex
    By kornkorn in forum Exceptions
    Replies: 1
    Last Post: September 8th, 2013, 11:33 PM
  2. input argument for webservice
    By neda.r in forum Web Frameworks
    Replies: 0
    Last Post: June 2nd, 2013, 05:58 AM
  3. Help With Null Pointer Exception
    By kendraheartt in forum What's Wrong With My Code?
    Replies: 17
    Last Post: August 15th, 2012, 10:41 PM
  4. Help with null pointer exception
    By Dr.HughMan in forum Exceptions
    Replies: 35
    Last Post: November 30th, 2011, 09:00 PM
  5. Null Pointer Exception?
    By SeanEE89 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 16th, 2011, 06:21 PM

Tags for this Thread