thyx 发表于 2017-2-21 23:32:22

为什么超出范围

本帖最后由 thyx 于 2017-2-22 00:24 编辑

class It {
       static int size;
       public It(int size) {
                        It.size=size;
          }
    private static java.util.Random rand = new java.util.Random();
    static DotInfo[][] dotlength =new DotInfo;
    public DotInfo[][] getDot(){
               
               
                for(int j = 0; j<size; j++){
                        for(int i = 0; i<size; i++){
                                dotlength=new DotInfo(j,i,rand.nextInt(6)+0);//dotInfo有三个值(x,y,color),color用一些随机的数字表示
                        }
                }
                return dotlength;
        }
        public void dot(){
                getDot();
                for(int i =0;i<dotlength.length;i++){
                        for(int s =0;s<dotlength.length;s++){
                                System.out.println(dotlength);
                        }
                }
        }
}


public class FloodIt{
        public static void main(String[] args) {
                It t= new It(5);
                t.dot();
        }
}


为什么超出范围
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
讲这行超出 dotlength=new DotInfo(j,i,rand.nextInt(6)+0);

零度非安全 发表于 2017-2-22 09:19:25

DotInfo 这个类咧?????
页: [1]
查看完整版本: 为什么超出范围