Results 1 to 4 of 4
Thread: Exporting to jar error
- 12-15-2011, 11:36 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
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.
I'm new to java and can't find out what is wrong. I also uploaded my project files.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
Thanks for any help!
game.zip
- 12-16-2011, 12:55 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: Exporting to jar error
Evidently the read() method was passed null in the statement on line 11 of Texture.java.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)
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.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); } }
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.
- 12-16-2011, 07:34 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
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!
- 12-16-2011, 07:40 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Similar Threads
-
Exporting to jar error
By Sean2012 in forum EclipseReplies: 0Last Post: 12-15-2011, 11:32 PM -
Exporting to JAR and running in cmd
By JonnySnip3r in forum New To JavaReplies: 2Last Post: 01-31-2010, 06:41 PM -
Problem when exporting to CSV
By deepusrp in forum New To JavaReplies: 10Last Post: 06-26-2009, 09:33 AM -
Greenfoot exporting in .jar?
By sciguy77 in forum New To JavaReplies: 0Last Post: 01-18-2009, 07:06 PM -
Exporting my project
By Nim in forum CLDC and MIDPReplies: 3Last Post: 11-04-2008, 11:53 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks