i working tutorial on youtube entitled:
how make java "tower defence" game? part 1 of 3! - "layouting"
the coding working error keeps popping up
exception in thread "awt-eventqueue-0" java.lang.arrayindexoutofboundsexception
when run code can me please? here code
import java.awt.*; public class store { public static int shopwidth = 8 ; public static int buttonsize = 32; public rectangle[] button = new rectangle[shopwidth]; public store() { define(); } public void define(){ for(int i=0;1<button.length;i++){ button[i] = new rectangle((screen.mywidth/2)-((shopwidth*buttonsize)/2), 10, buttonsize, buttonsize); } } public void draw(graphics g){ for(int i=0;1<button.length;i++){ g.fillrect(button[i].x, button[i].y, button[i].width, button[i].height); } } }
it simple typo.
try i<button.length
instead of 1<button.length
...
as loop not end until exception occurs.
Comments
Post a Comment