[Solved] Issue with LWJGL Space Inaders Example

Hello,

I am trying to run the Space Invaders example from the LWJGL wiki. This one.
http://lwjgl.org/wiki/index.php?title=Space_Invaders_Example_Game

What is odd to me is that there is no red 'x’s in Eclipse and it seams like I have
properly attached all the libraries right.

Here is the error it gives me.

Fri Nov 08 02:26:45 CST 2013 INFO:Slick Build #237
Fri Nov 08 02:26:45 CST 2013 INFO:LWJGL Version: 2.9.0
Fri Nov 08 02:26:45 CST 2013 INFO:OriginalDisplayMode: 1440 x 900 x 32 @0Hz
Fri Nov 08 02:26:45 CST 2013 INFO:TargetDisplayMode: 800 x 600 x 0 @0Hz
Fri Nov 08 02:26:45 CST 2013 INFO:Starting display 800x600
Fri Nov 08 02:26:46 CST 2013 INFO:Use Java PNG Loader = true
Fri Nov 08 02:26:46 CST 2013 INFO:Controllers not available
Exception in thread "main" java.lang.RuntimeException: Resource not found: testdata/alphamap.png
	at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:185)
	at org.newdawn.slick.Image.<init>(Image.java:192)
	at org.newdawn.slick.Image.<init>(Image.java:166)
	at org.newdawn.slick.Image.<init>(Image.java:154)
	at org.newdawn.slick.Image.<init>(Image.java:132)
	at org.newdawn.slick.tests.AlphaMapTest.init(AlphaMapTest.java:33)
	at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
	at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
	at org.newdawn.slick.tests.AlphaMapTest.main(AlphaMapTest.java:79)

Thank you so much for reading this and trying to help. :slight_smile:

Did you find and load the resource files mentioned in the instructions?

The error code is saying that it can’t locate alphamap.png, which is a graphical resource used in the program. It may be that you have to create/add the filefolder “testdata” to the project and move the resources to that location. Have you loaded resources before?

I ran this tutorial once, I think it was in August, but have since deleted the project, and can’t remember exactly what all I had to do to get it to work.

It’s possible I didn’t load it right? I just made a folder in my workspace project folder called ‘res’ and put all the files that came with lwjgl in there. I also made a folder called testdata because I thought that might work, though it didn’t. The odd thing is that there is no file named ‘alphamap.png’ that I could find with the lwjgl resources. Is it possible this has to do something with the slick library?? There were no errors with the red Xs which it normally does when I don’t have the correct packages imported. :stuck_out_tongue:

EDIT: wow, I just found that this same exact error is happening for me on a completely different project folder. What is odd is that this other project is not using the slick libraries at all…

You are not alone…


(LOL–I was doing a search on alphamap.png and the above came up.)

BTW, questions about loading resources come up a LOT, as getting the addressing right, especially in jars. So, it doesn’t surprise me that the problem comes up in an entirely separate context.

The Java Tutorials section that deals with resource loading is here:
http://download.oracle.com/javase/tutorial/uiswing/components/icon.html
They are discussing this in the context of loading an image into an icon, but the part about loading images in general and about the relative addressing still pertain.

You might consider going through this set of Space Invaders tutorials instead:
http://www.cokeandcode.com/main/tutorials/space-invaders-101/

There are four versions, and if I remember correctly, 104 uses LWJGL. I recall getting 3 of them to work–I remember skipping one of them.

I also wonder if the file is part of the Slick download, if there are some resources packed with the full distribution.
http://slick.ninjacave.com/

The writer Kevin Glass is listed with JGO, and often comments/contributes. But since he officially handed this code off, he might not wish to be asked maintenance questions. I really don’t know him well enough to say.

I couldn’t explain in depth why it occurs but I believe your issue might be the following.

You can make Source Folders or regular Folders while in Eclipse.

If you have a regular folder you will need to do “res/testdata/alphamap.png”.
If you have a source folder you can do “testdata/alphamap.png”.

So try “res/testdata/alphamap.png” and if that doesn’t work, post a screenshot.

Good luck.

Hi gmmaster, you are getting that error, because you are not running your own main method.

The slick library contains numerous example programs, each with its own main method.

At the time you first attempted to run your code, you may not have had focus on the editor or may have had another class open, so eclipse couldn’t find a main method.
This makes it search the build path for a main method, and it finds all those inside Slick and sorts them alphabetically, and picks the first (it may have shown a dialog too).
So you are actually running AlphaMapTest.java, it says that in the stack trace too, and as another feature of eclipse it remembers which file you ran last, so it keeps running that when you click the run button.

A simple solution is to open your own class in the editor, right click in the editor, and run it from there, this it should remember too, so doing it once should be enough.

Thank you everyone!!

Especially Magn919 for the solution and easy fix and philfrei for all the links and info.