Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

When ever I run this, I get the error

Exception in thread "main" java.lang.IllegalArgumentException: input == null!

I tried many different solutions including moving parts of the code around and removing other things which each broke some other part. I also tried .getResourceAsStream.

package gfx;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

public class SpriteSheet {

public String path;
public int width;
public int height;

public int[] pixels;


public SpriteSheet(String path) {
    BufferedImage image = null;


    try {
    image = ImageIO.read(SpriteSheet.class.getResource(path));
        } catch (IOException e) {
            e.printStackTrace();
        }


    if(image == null){
        return;
    }


    this.path = path;
    this.width = image.getWidth();
    this.height = image.getHeight();    

    pixels = image.getRGB(0, 0, width, height, null, 0, width);

    for(int i = 0; i <= pixels.length;i++){
        pixels[i] = (pixels[i] & 0xff)/64;
    }


    for(int i = 0;i < 8;i++) {
        System.out.println(pixels[i]);
    }


}       
}
share|improve this question
1  
Another "please debug my code for me" question. – mh01 Apr 6 at 22:52
Is that your only code? Or do you have a main class? – Savlon Apr 6 at 23:55
I have a main class, but it doesn't give me any errors when I try to run. – Hotshot Apr 7 at 0:48
@Hotshot I personally don't like to use the "blahblah.class.getResource(path) method because it can be confusing sometimes. Maybe give the actual path in string format a try. i.e image = ImageIO.read(new File("res/" + path + ".png")); I'm not sure what IDE you are using, however, the "res" folder should be in the SAME folder as the src folder. – Savlon Apr 7 at 3:27
See gamedev.stackexchange.com/a/50967/2158 for information on how to load resources in Java. Your problem might be that you are using Class.getResource() instead of ClassLoader.getResource() – msell Apr 7 at 6:22

closed as too localized by mh01, Byte56, Josh Petrie, Patrick Hughes, msell Apr 7 at 6:18

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

Verify the path to your texture is accurate. Also, consider doing some reading on how exceptions work, and why you placed the try/catch block around your sprite creation function call.

share|improve this answer
the try/catch block must be placed around the ImageIO.read() method. – Savlon Apr 7 at 3:23
I understand, I'm just trying to lead them in the right direction to understand exceptions rather than simply doing it because an example says it is necessary. – Evan Apr 7 at 5:05
ahhh I see, sweet as :) – Savlon Apr 7 at 5:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.