Java 二维数组中的错误ArrayOutOfBoundException

Java 二维数组中的错误ArrayOutOfBoundException,java,Java,我在第110行得到错误ArrayOutOfBoundException:15: System.out.println(coordinates[k][l]); 尝试运行此代码时: import TUIO.*; TuioProcessing tuioClient; int cols = 15, rows = 10; boolean[][] states = new boolean[cols][rows]; String[][] coordinates = new String[cols][r

我在第110行得到错误
ArrayOutOfBoundException:15

System.out.println(coordinates[k][l]);  
尝试运行此代码时:

import TUIO.*;
TuioProcessing tuioClient;

int cols = 15, rows = 10;
boolean[][] states = new boolean[cols][rows];
String[][] coordinates = new String[cols][rows]; 
int videoScale = 50;

// these are some helper variables which are used
// to create scalable graphical feedback
int x, y, i, j, k, l;
float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
PFont font;

boolean verbose = false; // print console debug messages
boolean callback = true; // updates only after callbacks



void setup(){
  size(500,500);
noCursor();

  noStroke();
  fill(0);

  // periodic updates
  if (!callback) {
    frameRate(60); //<>//
    loop();
  } else noLoop(); // or callback updates 

  font = createFont("Arial", 18);
  scale_factor = height/table_size;

  // finally we create an instance of the TuioProcessing client
  // since we add "this" class as an argument the TuioProcessing class expects
  // an implementation of the TUIO callback methods in this class (see below)
  tuioClient  = new TuioProcessing(this);

}
void draw(){
  // Begin loop for columns
  for ( k = 0; k < cols; k++) {
    // Begin loop for rows
    for ( l = 0; l < rows; l++) {

      // Scaling up to draw a rectangle at (x,y)
      int x = k*videoScale;
      int y = l*videoScale;

      fill(255);
      stroke(0);


for (int i = 0; i < cols; i++) {
  for (int j = 0; j < rows; j++) { 

 coordinates[i][j] = String.valueOf((char)(i+65)) + String.valueOf(j).toUpperCase();

  }
}
    /*  
      //check if coordinates are within a box (these are mouse x,y but could be fiducial x,y)
      //simply look for bounds (left,right,top,bottom)
      if( (mouseX >= x &&  mouseX <= x + videoScale) && //check horzontal
          (mouseY >= y &&  mouseY <= y + videoScale)){
        //coordinates are within a box, do something about it
       System.out.println(coordinates[k][l]); 
        //you can keep track of the boxes states (contains x,y or not) 
        states[k][l] = true;

        if(mousePressed) println(k+"/"+l);

      }else{

        states[k][l] = false;

      }

*/
      rect(x,y,videoScale,videoScale); 
    }
  }

   textFont(font,18*scale_factor);
  float obj_size = object_size*scale_factor; 
  float cur_size = cursor_size*scale_factor; 

  ArrayList<TuioObject> tuioObjectList = tuioClient.getTuioObjectList();
  for (int i=0;i<tuioObjectList.size();i++) {
     TuioObject tobj= tuioObjectList.get(i);
     stroke(0);
     fill(0,0,0);
     pushMatrix();
     translate(tobj.getScreenX(width),tobj.getScreenY(height));
     rotate(tobj.getAngle());
     rect(-obj_size/2,-obj_size/2,obj_size,obj_size);
     popMatrix();
     fill(255);
     text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
     System.out.println(tobj.getSymbolID ()+ " " + tobj.getX());

     if( ( tobj.getX()>= x &&  tobj.getX() <= x + videoScale) && //check horzontal
          (tobj.getY() >= y &&  tobj.getY() <= y + videoScale)){
        //coordinates are within a box, do something about it
       System.out.println(coordinates[k][l]); 
   }
rect(x,y,videoScale,videoScale);
}
}
// --------------------------------------------------------------
// these callback methods are called whenever a TUIO event occurs
// there are three callbacks for add/set/del events for each object/cursor/blob type
// the final refresh callback marks the end of each TUIO frame
// called when an object is added to the scene

/* void addTuioObject(TuioObject tobj) {
  if (verbose) println("add obj "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());
}

 // called when an object is moved
void updateTuioObject (TuioObject tobj) {
  if (verbose) println("set obj "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY());
}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
  if (verbose) println("del obj "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
}
*/

// --------------------------------------------------------------
// called at the end of each TUIO frame
void refresh(TuioTime frameTime) {
  if (verbose) println("frame #"+frameTime.getFrameID()+" ("+frameTime.getTotalMilliseconds()+")");
  if (callback) redraw();
}
导入TUIO.*;
TuioProcessing tuioClient;
int cols=15,rows=10;
布尔[][]状态=新的布尔[cols][rows];
字符串[][]坐标=新字符串[cols][rows];
int videoScale=50;
//这些是使用的一些辅助变量
//创建可伸缩的图形反馈
int x,y,i,j,k,l;
浮动光标_size=15;
浮动对象大小=60;
浮动台_尺寸=760;
浮动比例系数=1;
字体;
布尔详细值=false;//打印控制台调试消息
布尔回调=true;//仅在回调后更新
无效设置(){
尺寸(500500);
noCursor();
仰泳();
填充(0);
//定期更新
如果(!回调){
帧率(60)////
loop();
}else noLoop();//或回调更新
font=createFont(“Arial”,18);
比例系数=高度/桌子尺寸;
//最后,我们创建一个TuioProcessing客户机的实例
//由于我们将“this”类添加为TuioProcessing类所期望的参数
//此类中TUIO回调方法的实现(请参见下文)
tuioClient=新的TuioProcessing(this);
}
作废提款(){
//开始列的循环
对于(k=0;k如果((mouseX>=x&&mouseX=y&&mouseY您试图在以下循环之外使用变量
k
l
-

  for ( k = 0; k < cols; k++) {
    // Begin loop for rows
    for ( l = 0; l < rows; l++) {

或者你不想在那里结束
k
l
循环(我在这篇文章开头提到的那些循环)?你没有注释掉那部分吗?

变量
k
的值在这个for循环的末尾是15

for ( k = 0; k < cols; k++) {
// Begin loop for rows
     for ( l = 0; l < rows; l++) {

       // Scaling up to draw a rectangle at (x,y)
       int x = k*videoScale;
       int y = l*videoScale;

       fill(255);
       stroke(0);


        for (int i = 0; i < cols; i++) {
          for (int j = 0; j < rows; j++) { 

            coordinates[i][j] = String.valueOf((char)(i+65)) +      String.valueOf(j).toUpperCase();

          }
        }
        rect(x,y,videoScale,videoScale); 
     }
   }
这就是为什么你会有例外


希望这有帮助。

请在这里显示第110行中的内容。draw()中的前两个循环结束于函数的末尾-这就是您要做的吗?(第三个和第四个循环在第二个循环内)@kiruwka第110行是我后面引用的行
for ( k = 0; k < cols; k++) {
// Begin loop for rows
     for ( l = 0; l < rows; l++) {

       // Scaling up to draw a rectangle at (x,y)
       int x = k*videoScale;
       int y = l*videoScale;

       fill(255);
       stroke(0);


        for (int i = 0; i < cols; i++) {
          for (int j = 0; j < rows; j++) { 

            coordinates[i][j] = String.valueOf((char)(i+65)) +      String.valueOf(j).toUpperCase();

          }
        }
        rect(x,y,videoScale,videoScale); 
     }
   }
System.out.println(coordinates[k][l]);