• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

IllegalArgumentException

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator





Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1400)
at Level.<init>(Level.java:16)
at Game.<init>(Game.java:37)
at Game.main(Game.java:107)


I am getting an error like this. How can I fix it? I tried everything. Under my project, I have two folders src and res. I uploaded my png image to my res folder but this error occurs.


 
Marshal
Posts: 76415
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem isn't in this code. The problem is in somebody passing null where they shouldn't. Please supply more details including the line where the exception is thrown.
 
Master Rancher
Posts: 4271
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the problem pretty definitely *is* connected to this code, at least partly.  Following the stack trace, we can see that when you call new Level("/map/map.png"), that passes "/map/map.png" to the Level constructor, as the value of path.  That means when we get to the line that throws the exception:

it's equivalent to

and the problem is that getResource is returning null - so the ImageIO.read() method is getting a null, and complaining about it.  Which probably means either the file doesn't exist at /map/map.png, or you're having problems accessing it.  It sounds like you're putting the file in a resources folder res, but giving it an absolute path name - I'm not sure how that's intended to work.  But try changing the path you pass to getClass().getResource() method, or try another way of locating the file (e.g. with a File object).
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic