java.lang.arrayoutofboundexception长度:10索引:10

java.lang.arrayoutofboundexception长度:10索引:10,java,android,arrays,processing,Java,Android,Arrays,Processing,我正在为android设备制作一个游戏。我正在使用我手机的传感器。我正在处理这个应用程序 但我对数组有个问题。 我想检查椭圆是否在数组中。但似乎我有一个错误。我已经检查过j*40&-yy+height-25i*40&&xx+width/2j*40&&yy+height/2=width | | xx+width/11=height | |-yy+height-25数组中的第一个值具有索引[0],因此第十个值将位于[9],而不是[10]。如果尝试引用数组[array.length](在您的情况下数组

我正在为android设备制作一个游戏。我正在使用我手机的传感器。我正在处理这个应用程序

但我对数组有个问题。 我想检查椭圆是否在数组中。但似乎我有一个错误。我已经检查过j*40&-yy+height-25i*40&&xx+width/2j*40&&yy+height/2如果(xx+width/11>=width | | xx+width/11=height | |-yy+height-25数组中的第一个值具有索引
[0]
,因此第十个值将位于
[9]
,而不是
[10]
。如果尝试引用
数组[array.length]
(在您的情况下
数组[10]
),您将遇到异常


也许值得你看看at

你开始从0开始计数,而不是1。你的数组有10个元素,但最后一个元素的索引9不是太多的代码。把它分解一下。这么多神奇的数字。首先,感谢这些消息,然后我不得不说,我是开发世界中真正的乞丐,我知道有一些问题,我想改进爱我自己,如果我的解释不清楚,我也很抱歉,我会尝试纠正这个!无论如何,我会尝试看看你说的stefan。所以,我必须理解在
plateau[int((xx+width/11)/(hateurrange+11))][int(-yy+height-25)/largeurColonne中‌​)]==0
my数组长度低于(xx+width/11)/HateUrRange+11?的结果?。。
  //VARIABLE USED      
    int colonnes = 10;
    int lignes= 10;
    int[][] plateau; // tableau 2D
    int posX_tabl;
    int posY_tabl;
    int x_balle;
    int y_balle;
    float largeurColonne = width/colonnes;
    float hateurRangee = height/lignes;
    float accelerometerX, accelerometerY, accelerometerZ;
    float xx=width/2;
    float yy=height-(height/10);
    float vxx=0;
    float vyy=0;
    float axx=0;
    float ayy=0;

    /*-----------------------------------------SETUP--------------------------------------------------*/
    void setup() {
      smooth();
      sensor = new KetaiSensor(this);
      sensor.start();
      orientation(LANDSCAPE);
      plateau = new int[colonnes][lignes];
      creer_plateau();
    }

    /*-----------------------------------------DRAW--------------------------------------------------*/
    void draw() {
      //Création du menu principal
      if (menu == true) {
        creer_plateau();
        menu();
      }
      //Création du jeu
      else if (jouer==true) {
        nettoyer();
        dessine_plateau();
        calcul_gravite();
        ellipse(  xx+width/11,  - yy+height-25, 40, 40);
        calculer_position();
        definir_balle();
        //Création des menus recommencer et option
      } else if (reco==true) {
        reco();
      } else if (option == true) {
        background(0);
        option();
      }
      mouseReleased = false;
    }

    void mousePressed() {
      mouseReleased = false;
    }
    void mouseReleased() {
      mouseReleased = true;
    }


    /*---------------------------INIT ARRAY-----------------*/
    //Create random value for random case in the game
    void creer_plateau() {
      int aleacouleur;
      for (int i=0; i < colonnes; i++) {
        for (int j=0; j < lignes; j++) {
          aleacouleur = (int)(random(0, 3));
          if (aleacouleur == 0) {
            plateau[i][j]=0;
          } else {
            plateau[i][j]=1;
          }
        }
        plateau[0][9] = 2;
        plateau[9][0] = 3;
      }
    }

    /*-----------------------------DRAW ARRAY------------*/
    //Draw the array according to the random value
    void dessine_plateau() {
      for (int i=0; i < colonnes; i++) {
        for (int j=0; j < lignes; j++) {
          if (plateau[i][j] == 0) {
            fill(0);
          } 
          if (plateau[i][j] == 1) {
            fill(255);
          }
          if (plateau[i][j]==2) {
            fill(255, 255, 0);
          }
          if (plateau[i][j]==3) {
            fill(0, 255, 0);
          }
          float x = i*largeurColonne;
          float y = j*hateurRangee;
          rect( x+1, y+1, largeurColonne-2, hateurRangee-2 );
        }
      }
    }

    /*---------------------------CHECK POSITION ELLIPSE-----------------------*/
// THIS FUNCTION IS PROBABLY USELESS
    //We Watch where is the ellipse
    void calculer_position() {
      for ( int j=0; j< 10; j++) {
        for (int i=0; i<10; i++) {
          if ( xx+width/11> i*40 && xx+width/11< i*40+40 && - yy+height-25 > j*40 && - yy+height-25 < j*40+40) {
            posX_tabl = i;
            posY_tabl = j;
          }
        }
        //if ( xx+width/2> i*40 &&  xx+width/2 < i*40+40 && - yy+height/2 > j*40 && - yy+height/2 < j*40+40)
      }
    }

    /*----------------CALCUL GRAVITE----------------------------*/
    void calcul_gravite() {
      vxx=vxx+axx;
      vyy=vyy+ayy;
      xx=xx+vxx*0.1;
      yy=yy+vyy*0.1;
      fill(0, 250, 0);
      text(vxx, 100, 100);
        if (xx+width/11>= width || xx+width/11 <= 0) {
        vxx=-0.8*vxx;
      }
      if (-yy+height-25 >= height || -yy+height-25 <= 0) {
        vyy=-0.8*vyy;
      }
    }

    /*----------------DEF BALLE--------------------------------*/
    //THERE IS THE PROBLEM WITH THE ARRAY IF U CAN HELP ME AND IF U HAVE QUESTION ABOUT THE CODE U CAN ASK ME
    void definir_balle() {
      if (plateau[int((xx+width/11)/(hateurRangee+11))][int((-yy+height-25)/largeurColonne)]==0) {
        text("loose", 50, 50);
      } else if (plateau[int((xx+width/11)/(hateurRangee+11))][int((-yy+height-25)/largeurColonne)]==3) {
        text("WIN", 50, 50);
      }


//this part was only a try 
      /*if (plateau[posX_tabl][posY_tabl]==0)
      {
        print("game over \n");

        jouer=false;
        reco=true;
        menu=false;
      } else if  (plateau[posX_tabl][posY_tabl]==1) {
        //print("courage \n");
      } else if (plateau[posX_tabl][posY_tabl]==3) {
        //print("gg wp \n");
      }*/
    }