鱼C论坛

 找回密码
 立即注册
查看: 3044|回复: 1

为什么超出范围

[复制链接]
发表于 2017-2-21 23:32:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 thyx 于 2017-2-22 00:24 编辑
  1. class It {
  2.          static int size;
  3.          public It(int size) {
  4.                         It.size=size;
  5.             }
  6.     private static java.util.Random rand = new java.util.Random();
  7.     static DotInfo[][] dotlength =  new DotInfo[size][size];
  8.     public DotInfo[][] getDot(){
  9.                
  10.                
  11.                 for(int j = 0; j<size; j++){
  12.                         for(int i = 0; i<size; i++){
  13.                                 dotlength[j][i]=new DotInfo(j,i,rand.nextInt(6)+0);//dotInfo有三个值(x,y,color),color用一些随机的数字表示
  14.                         }
  15.                 }
  16.                 return dotlength;
  17.         }
  18.         public void dot(){
  19.                 getDot();
  20.                 for(int i =0;i<dotlength.length;i++){
  21.                         for(int s =0;s<dotlength[i].length;s++){
  22.                                 System.out.println(dotlength[i][s]);
  23.                         }
  24.                 }
  25.         }
  26. }


  27. public class FloodIt{
  28.         public static void main(String[] args) {
  29.                 It t= new It(5);
  30.                 t.dot();
  31.         }
  32. }
复制代码


为什么超出范围
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
讲这行超出 dotlength[j]=new DotInfo(j,i,rand.nextInt(6)+0);
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-2-22 09:19:25 | 显示全部楼层
DotInfo 这个类咧?????
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 22:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表