Results 1 to 4 of 4
Thread: OutOfBoundsException
- 12-18-2007, 04:28 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 17
- Rep Power
- 0
OutOfBoundsException
here's a question:
in one class I have the method:
static public StartBoard[] finalBoard()
{
StartBoard[] temp = new StartBoard[32];
.
.
.
return temp;
}
and in another class, inside the main method, I wrote:
StartBoard[] try2 = new StartBoard[32];
try2 = StartBoard.finalBoard();
for (int i = 0; i<32; i++)
System.out.println(try2[i].getType());
and I got the following runtime error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32
at chess.StartBoard.finalBoard(StartBoard.java:74)
at chess.Play.main(Play.java:21)
I remember learning something about "contracts" with variables to be instance of a certain non-primitive type, is that the solution? and if so, how do I use it?
thanks a head
fenigerhave a good one - Day I mean...
- 12-18-2007, 04:30 PM #2
Member
- Join Date
- Dec 2007
- Posts
- 17
- Rep Power
- 0
maybe its important to know to solve:
the first code snippet is actually inside:
public enum StartBoard {... }have a good one - Day I mean...
- 12-19-2007, 05:38 AM #3
Looks like you went past the end of the array, viz, element index 31, onJava Code:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32 at chess.StartBoard.finalBoard(StartBoard.java:74) at chess.Play.main(Play.java:21)
line 74 in your code.
Java Code:// These //StartBoard[] try2 = new StartBoard[32]; //try2 = StartBoard.finalBoard(); // line 21 here? // can be written StartBoard[] try2 = StartBoard.finalBoard(); // This looks okay. for (int i = 0; i<32; i++) System.out.println(try2[i].getType()); ... public enum StartBoard { static public StartBoard[] finalBoard() { StartBoard[] temp = new StartBoard[32]; . . // line 74 must be in here... . return temp; }
- 12-20-2007, 01:31 AM #4
Member
- Join Date
- Dec 2007
- Posts
- 17
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks