毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

小拼图游戏Exception in thread "main"java.lang.ArrayIndexOutofBoundsException

更新时间:2012-5-25:  来源:毕业论文
g.setFont(myFont);
FontMetrics myFm=g.getFontMetrics();
  g.setColor(Color.white); //change color so that string displayed will be white
  g.drawString(tileNumber,this.getWidth()/2-myFm.stringWidth(tileNumber)/2,this.getHeight()/2+myFm.getHeight()/2); //keep the string in the center position
}
  public void setTileNumber(String tileNumber){
this.tileNumber = tileNumber;
this.repaint(); // invoke repaint() fuction to set the tile
  }


/** 
* This method returns tileNumber to SlidingPuzzle class to locate a PuzzleTile. 
*
* @return tileNumber The number of PuzzleTile displays.
*/
public String getTileNumber(){
return tileNumber;
}

  public PuzzleTile(int number) {
  super();
if (number == 0) {
  this.setBackground(Color.white);
  }
else {
  this.setBackground(Color.darkGray);
  }
this.tileNumber = "" + number;
  }

  // You will need to provide more methods to interact with your 
  // main program. 
}

比较明显了,Exception in thread "main"java.lang.ArrayIndexOutofBoundsException,数组越界,你所期望取的那个数组位置不存在,譬如你整个数组大小也就[2,2]你却取了[2,3]或[-1,x].
这种异常就不帮你找哪里出错了, 果断debug一下吧,不出几分钟你就会找到问题原因了。
public static int level=3;
  public PuzzleTile[][] XueButtonArray= new PuzzleTile[level-1][level-1];
 你定义了一个[2][2]的二维数组,
for(int i=0;i<level;i++)

循环的时候却有3个,当然数组下标越界

上一页  [1] [2] [3] 

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©chuibin.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。