Results 1 to 2 of 2
  1. #1
    chirikoo is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Default ArrayOutOfBoundsException in Bluej?

    We've been asked to create this SudokuChecker program, and whenever I enter a valid solution, this error keeps popping up.
    This only happens when I check the regions(the individual 3x3 grids in the 9x9)
    Here is my code:
    public boolean checkRegions()
    {
    int startColumns = 0;
    int finalColumns = 3;
    int startRows = 0;
    int finalRows = 3;
    for(int y=0; y<3; y++)
    {
    for(int z=0; z<3; z++)
    {
    boolean presentNumber[] = new boolean[9];
    for(int j=0; j<9; j++)
    {
    presentNumber[j] = false;
    }
    for(int rows=startRows; rows<finalRows; rows++)
    {
    for(int columns=startColumns; columns<finalColumns; columns++)
    {
    for(int k=0; k<9; k++)
    {
    if(Sudoku[rows][columns] == k+1 && presentNumber[k])
    {
    return false;
    }
    else if(Sudoku[rows][columns] == k+1 && !presentNumber[k])
    {
    presentNumber[k] = true;
    }
    }
    }
    }
    startColumns += 3;
    finalColumns += 3;
    }
    startRows += 3;
    finalRows += 3;
    startColumns += 3;
    finalColumns += 3;
    }
    return true;
    }
    Error message pops up at the bolded part.
    Any help?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default Re: ArrayOutOfBoundsException in Bluej?

    Print out the values for startColumns, finalColumns, startRows and finalRows at each loop pass; you are forgetting to reset the rows/columns (I can't exactly see which ones without proper indentation).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Running from BlueJ
    By ignign0kt in forum New To Java
    Replies: 0
    Last Post: 05-06-2011, 12:43 PM
  2. Need help with blueJ
    By samd89 in forum Other IDEs
    Replies: 6
    Last Post: 12-06-2010, 05:59 PM
  3. BlueJ help
    By Cid17 in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 07:38 PM
  4. help using BlueJ
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:07 AM
  5. BlueJ 2.2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-07-2007, 02:28 PM

Posting Permissions

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