How to clear rows in Tetris?

I’m doing an java assignment on tetris and this little bit of code is giving me trouble. I can’t seem to figure out why my code for clearing completed lines is not working. Can some one please help me out?

public int clearLines() {     int numCleared = 0;      while(true)      {          int index = -1;          for(int j = 0; j< 22; j++)          {              int cnt = 0;              for(int i = 0; i < 10; i++)              {                  cnt += board[j][i] != 0 ? 1 : 0;               }              if(cnt == 10)              {                  index = j;                  break;              }          }          if(index == -1)          {              break;          }          int[][]temp = new int[22][10];          for(int i = 0; i < 22; i++)          {              for(int j = 0; j < 10; j++)              {                  temp[i][j] = board[i][j];              }          }          for(int i = 0; i < index + 1; i++)          {              for(int j = 0; j < 10; j++)              {                  if(i == 0)                  {                      board[i][j] = 0;                  }                  else                  {                      board[i][j] = temp[i - 1][j];                  }              }          }          linesCleared++;          numCleared++;      }      return numCleared; }