Java unreachable code error -
i following tutorial on youtube , when got part i'm supposed use "this.path" , things that, seem getting errors. can't seem find solution this.
here link 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 = 0; <= pixels.length;i++){ pixels[i] = (pixels[i] & 0xff)/64; } for(int = 0;i <= 8;i++) { system.out.println(pixels[i]); } } }
your error here:
if(image == null);{ return; } you have additional semicolon after if statement. should instead be:
if(image == null) { return; } the semicolon ends if statement; in other words, if(image == null), nothing, run return;
java not allow unreachable code. since return statement being run regardless of if-condition, past point cannot reached.
Comments
Post a Comment