Results 1 to 7 of 7
Thread: cannot load textures
- 01-29-2010, 01:56 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 3
- Rep Power
- 0
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!
- 01-29-2010, 06:48 PM #2
This usually means that the class loader could not find the resource it was given so the ImageIO.read method returns null.Java Code:Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(ImageIO.java:1378)
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);
- 02-01-2010, 01:13 AM #3
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
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.
- 02-01-2010, 04:54 PM #4
Member
- Join Date
- Jan 2010
- Posts
- 3
- Rep Power
- 0
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!
- 02-01-2010, 06:58 PM #5
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
getSystemResource may be the wrong method
In my project with main class "Tagger", I use
where path is a simple name like foo.pngJava Code:URL imgURL = Tagger.class.getResource(path)
and foo.png resides in the same directory as Tagger.class.
- 02-01-2010, 07:17 PM #6
Member
- Join Date
- Jan 2010
- Posts
- 3
- Rep Power
- 0
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:
but in my case, I work with textures. And I don't know how this line worksJava Code:ImageIcon sid = new ImageIcon(Puzzle.class.getResource("icesid.png"));
to load .png
any ideas? see the code Painting in Swing the example "Textures"Java Code:URL url1 = ClassLoader.getSystemResource("texture1.png");
- 02-01-2010, 07:24 PM #7
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
Similar Threads
-
cant load the EmbeddedDriver
By kulangotski in forum Advanced JavaReplies: 6Last Post: 02-22-2009, 04:01 AM -
How to load new libraries
By Manfizy in forum NetBeansReplies: 2Last Post: 02-11-2009, 06:55 AM -
How can we load database?
By java19857 in forum New To JavaReplies: 5Last Post: 09-19-2008, 06:34 PM -
how to load a lot of files?
By gabriel in forum Java ServletReplies: 1Last Post: 08-07-2007, 06:04 PM -
Help with load image
By trill in forum New To JavaReplies: 1Last Post: 08-01-2007, 07:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks