Hello everyone. I'm currently exploring Java's GUI and trying a lot of codes now. I found a game GUI source code on the net. This program uses images to properly run. I can run the program now but it only displays black screen. It already have the folder for the images but I can't properly connect it to the program. Please, I need help. ._.

Dani AI

Generated

Brief diagnosis: the image loader is receiving no data (ImageIO.read is being handed a null input), so the draw routine ends up with nothing to paint and you see a black screen. As pointed out, seeing code helps, but the problem is almost always a wrong resource path or the image not being on the classpath.

Quick troubleshooting steps you can try immediately:

  • From the running app print out or test the file location to confirm the JVM can see it. Example (quick file-check):

    File f = new File("path/to/your/image.png");
    System.out.println(f.getAbsolutePath() + " exists? " + f.exists());
  • Prefer classpath-safe loading (works inside IDE and JARs). Use your class to fetch the resource and verify the URL/stream is not null before passing to ImageIO:

    URL u = MyClass.class.getResource("/com/example/resources/image.png");
    System.out.println(u);      // should not be null
    BufferedImage img = ImageIO.read(u);

Common causes and fixes: wrong relative vs absolute resource path (leading slash matters), case-sensitive filename mismatches, resources not copied into build output (move images into your source/resources folder and mark as resources in the IDE), or trying to load with new File(...) when the app is packaged as a JAR.

Since you mentioned multiple classes, check which class is calling getResource—relative paths without a leading slash are resolved against that class’s package. Add a null-check/log before drawing so a missing image produces a clear error message rather than a silent black screen.

Recommended Answers

All 5 Replies

Without seeing your code its impossible to say what's wrong with it.

Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!
        at javax.imageio.ImageIO.read(ImageIO.java:1362)
        at moon_lander.Framework.LoadContent(Framework.java:115)
        at moon_lander.Framework.GameLoop(Framework.java:162)
        at moon_lander.Framework.access$000(Framework.java:21)
        at moon_lander.Framework$1.run(Framework.java:90)

it shows that exception.
it really runs except that it only displays a black screen. o.o

Line 3 of that message tells you exactly where in your code it's going wrong. Hang on a minute while I start my psychic code reader that will allow me to see what that code says...

I just need help into properly placing the files and putting up the file paths of the folder that contains the images needed for this program.

it only has this
/moon_lander(the name of the folder)/resources/backgroundimg.jpeg

declared on the game.java source code.

it just happen that this code contains 6 classes...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.