Results 1 to 7 of 7
  1. #1
    zlatko is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default cannot load textures

    Hi! I am trying to run a program with textures from a swing tutorial on Painting in Swing and that's what I get:

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(ImageIO.java:1378)
    at Textures.paintComponent(Textures.java:47)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JC... and bla - bla - bla....

    Any ideas? Post me for details. Thanks!

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(ImageIO.java:1378)
    This usually means that the class loader could not find the resource it was given so the ImageIO.read method returns null.

    In your Painting in Swing article code for Textures:
    Java Code:
                URL url1 = ClassLoader.getSystemResource("texture1.png");
                ...
                // Try writing out the url here to see what the class
                // loader came up with
                System.out.println("url1 = " + url1);
    
                try {
                    bimage1 = ImageIO.read(url1);

  3. #3
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    If you are using netbeans,
    and if you have placed the textures in the src/ tree,
    and if you have NOT done build project,
    then you need to do build project
    to copy from the src/ tree to the build/ tree.

  4. #4
    zlatko is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    to zweibieren: first, thanks! second, I don't use NetBeans. I use a simple text redactor and the terminal to compile and run da progs. thanks anyway.

    to hardwired: I guess, that make sense. But the tutorial does not give any .png files to load like you may see here The Puzzle in Java Swing
    That means the line

    URL url1 = ClassLoader.getSystemResource("texture1.png");

    finds this texture.png somewhere in the system (getSystemResourse-Bla-Bla-Bla). I think the .pngs are in the swing's library or what? Sounds stupid. Anyway the println command you adviced gives

    Textures.java:45: operator + cannot be applied to java.net.URL

    I tried without plus sign, it gives another error.
    Last: the point is in the .png files location. Am I right?
    Thanks!

  5. #5
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    getSystemResource may be the wrong method

    In my project with main class "Tagger", I use
    Java Code:
    URL imgURL = Tagger.class.getResource(path)
    where path is a simple name like foo.png
    and foo.png resides in the same directory as Tagger.class.

  6. #6
    zlatko is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by zweibieren View Post
    foo.png resides in the same directory as Tagger.class.
    that's it, there are no .png files included... I knew it from the beginning. It seems like the tutorial is missing them. But: to include a .png file is used as you said:
    Java Code:
    ImageIcon sid = new ImageIcon(Puzzle.class.getResource("icesid.png"));
    but in my case, I work with textures. And I don't know how this line works
    to load .png
    Java Code:
                
    URL url1 = ClassLoader.getSystemResource("texture1.png");
    any ideas? see the code Painting in Swing the example "Textures"

  7. #7
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

Similar Threads

  1. cant load the EmbeddedDriver
    By kulangotski in forum Advanced Java
    Replies: 6
    Last Post: 02-22-2009, 04:01 AM
  2. How to load new libraries
    By Manfizy in forum NetBeans
    Replies: 2
    Last Post: 02-11-2009, 06:55 AM
  3. How can we load database?
    By java19857 in forum New To Java
    Replies: 5
    Last Post: 09-19-2008, 06:34 PM
  4. how to load a lot of files?
    By gabriel in forum Java Servlet
    Replies: 1
    Last Post: 08-07-2007, 06:04 PM
  5. Help with load image
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 07:16 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
  •