Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Post Array index out of bounds exception...

    Hey, this is throwing an ArrayIndexOutOfBoundsException back at me, and i dont understand why, could somebody please help?


    Java Code:
    import java.util.Scanner;
    
    public class ticTacToe { 
    
     private static int rows = 3;
     private static int columns = 3;
    
     
    public static String[][] board(int row, int col){
      String[][] cha = new String [col][row];
      for (int i = 0; i < col; i++)
      {
        for( int j = 0; j < row; i++)
        {
          cha[i][j] = "\u2732";
          
          
        }
      }
      return cha;
    }
    
    public static void display(String x[][]){
      for (int i = 0; i < x.length; i++){
        for ( int j = 0; j < x.length; i++){
          System.out.print(x[i][j]);
        }
        System.out.print( "\n" );
      }
    
    }
          
        
      public static void main(String[] args)
      {
    
      ticTacToe game = new ticTacToe();
      
      String grid[][] = board(rows, columns);
      
      display(grid);
      }
    
    }
    Last edited by NinjaRobotPanda; 01-30-2013 at 03:19 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Array index out of bounds exception...

    Please indicate by a comment in your code which line is throwing the exception, and also please show the complete exception text.

  3. #3
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: Array index out of bounds exception...

    reason of the exception is that in the inner loops you are incrementing 'i' instead of 'j'. Change that and it will work fine.
    Thanks!!!

Similar Threads

  1. Having a problem with my code
    By jman8910 in forum New To Java
    Replies: 1
    Last Post: 01-15-2013, 10:33 PM
  2. Problem with code
    By koryvandell in forum New To Java
    Replies: 4
    Last Post: 04-25-2011, 05:28 AM
  3. Replies: 0
    Last Post: 02-21-2011, 12:50 PM
  4. Replies: 9
    Last Post: 09-21-2010, 05:15 PM
  5. Problem with zero in my code
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 07:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •