Reputation: 1
I was following a tutorial on youtube and when I got to the part where I'm supposed to use "this.path" and things like that, however I seem to be getting errors. I can't seem to find any solution to this.
Here is a link to the video: http://www.youtube.com/watch?v=o7pfq0W3e4I
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.getResourceAsStream(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]);
}
}
}
Upvotes: 0
Views: 92
Reputation:
Your error is here:
if(image == null);{
return;
}
You have an additional semicolon after the if
statement. This should instead be:
if(image == null) {
return;
}
The semicolon ends the if statement; in other words, if(image == null)
, do nothing, then run return;
Java does not allow unreachable code. Since your return
statement is being run regardless of the if-condition, anything past that point cannot be reached.
Upvotes: 7