wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Minicraft - 2D Java Game - Help for Beginner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Minicraft - 2D Java Game - Help for Beginner" Watch "Minicraft - 2D Java Game - Help for Beginner" New topic
Author

Minicraft - 2D Java Game - Help for Beginner

Charles Olson
Greenhorn

Joined: Dec 20, 2011
Posts: 6

Hello! I just completed my first Java college course and I am eager to start making games in Java.

Notch, famed creator of Minecraft recently created a small 2D game in java called “minicraft” and the source code is available here:
http://www.ludumdare.com/compo/ludum-dare-22/?action=preview&uid=398

I imported the source in Eclipse as an existing project, but when I try to run the game, it throws the following errors:

Exception in thread "Thread-3" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1348)
at com.mojang.ld22.Game.init(Game.java:118)
at com.mojang.ld22.Game.run(Game.java:136)
at java.lang.Thread.run(Thread.java:722)


I would appreciate any help anyone can provide to teach me how to properly run this code.

Also if anyone knows a good tutorial on how to start making games in Java, I would appreciate it. I am currently just using the first couple links off of a google search to try to teach myself.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37970
    
  22
Welcome to the Ranch

You have got well-written code there, which protects itself from having nulls passed to it. And you have passed it a null. Please inspect the code round the line number shown, and where it was called from. Then you can find where the null comes from.
Charles Olson
Greenhorn

Joined: Dec 20, 2011
Posts: 6



This is the code producing the errors. I don't understand why it is causing errors. It's from ImageIO.class
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3426
    
  12
Charles Olson wrote:This is the code producing the errors. I don't understand why it is causing errors.

Well it's fairly obvious. The input variable must be null. Now you've got to go to line 118 of Game.java and see why the parameter being passed to this method is null.


Joanne
Charles Olson
Greenhorn

Joined: Dec 20, 2011
Posts: 6



I think it's having trouble accessing the /icons.png file

The icons.png file is there in the "res" folder, and the folder is in the java project in eclipse...what do you think needs to be changed?

Sorry if the solutions seem "obvious" to you...obviously they don't seem so to me, which is why I registered so I could ask for some help on basic questions. Thanks for your patience.
Charles Olson
Greenhorn

Joined: Dec 20, 2011
Posts: 6

I copied the images and other resources for the game into the main game package and then deleted the / on "/icons.png" and now it is working...I don't know why it was set up like this and why it had to be changed...but at least it works now

Except now none of the other resources work, because I need to find the slashes (/) in front of the resource names and delete them

Can anyone explain how to properly set/call the path to my resources in java/eclipse?
Charles Olson
Greenhorn

Joined: Dec 20, 2011
Posts: 6

I figured it out -

Go to "Run->Run configurations..." (in case of debug "Run->Debug configurations...")
Open Run (Debug) configuration which you use
Open "Classpath" tab
Select "User Entries" and click "Advanced..." on the right
In the opened window select "Add folder", point to your src/test/resources


Thanks for your help
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3426
    
  12
Charles Olson wrote:Sorry if the solutions seem "obvious" to you...obviously they don't seem so to me

I didn't say the solution was obvious, I said the problem was.
The original error was
Exception in thread "Thread-3" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1348)
at com.mojang.ld22.Game.init(Game.java:118)

The code you posted later

showed that that exception would be thrown when the input variable is null. That's how I knew what the problem was.

Maybe how I knew that you needed to look at how the method was called from line 118 of Game.java was not quite so obvious. I'll explain.
If you go back to the stack trace, you will see from the second line that the exception was thrown from line 1348 of ImageIO.java (that's what the bit in brackets mean). Go to the next line and you see that the read method was called from line 118 of Game.java. Keep following the stack trace like that and you will find the path that was followed by the code. Learning how to read stack traces is a very useful for debugging.
Charles Olson
Greenhorn

Joined: Dec 20, 2011
Posts: 6

Ah, I see now. Thank you for the explanation.
Adam Ashwal
Greenhorn

Joined: Dec 26, 2011
Posts: 1
For anyone looking at this, in the source code I got I followed the above instructions but pointed the folder just at res not src/test/resources. Question though, could anyone explain to me what this step is even doing?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Minicraft - 2D Java Game - Help for Beginner
 
Similar Threads
Bowling League: first story
Unresolved compilation problems: cannot be resolved to a typ
Good Java Game Tutorial
Video Game club
jar file error