Results 1 to 9 of 9
- 06-03-2011, 10:32 AM #1
Member
- Join Date
- Jun 2011
- Location
- Tsukuba, Japan
- Posts
- 63
- Rep Power
- 0
array index out of bounds exception, AGAIN!
I am using this code, somewhere in the middle of a huge program.
And I am getting an out_of_bounds exception. Is this command allowed? Where could my array possibly be going awry?Java Code:else if(ev.getSource() == okButton1){ if(a<neigh1.s)a++; for( int i=0; i<(810/30); i++) { for( int j=0; j<(630/30); j++) { rules[a-1][i][j]=exch3.rulbas[i][j];}}}
I have initialized them as follows:
andJava Code:public static int a=0; public rule2 exch3; public static int rules[][][]= new int[neigh1.s][810/30][630/30];
Java Code:class rule2 implements Serializable { public int rulbas[][];....etc
- 06-03-2011, 11:31 AM #2
1. Learn to not use magic numvbers.
2. Learn how to format code for readability: Code Conventions for the Java(TM) Programming Language: ContentsJava Code:for( int i = 0; i < rules[a-1].length; i++) { for( int j = 0; j < rules[a-1][i].length; j++) { rules[a-1][i][j] = exch3.rulbas[i][j]; } }
db
- 06-03-2011, 11:34 AM #3
Java has statements. Not commands.Is this command allowed?
db
- 06-03-2011, 04:30 PM #4
Member
- Join Date
- Jun 2011
- Location
- Tsukuba, Japan
- Posts
- 63
- Rep Power
- 0
Okay. Well I didn't use magic numbers in the statement, simply replaced the variable with the value it contained for better understanding.
And the code fragment didn't work, obviously, since one variable was simply replaced with another. I am asking if there is some hierarchical issues I haven't thought about.
Also is there a simpler way of putting the values of many 2D matrices into a 3D matrix?
- 06-03-2011, 05:29 PM #5
- 06-03-2011, 06:01 PM #6
Member
- Join Date
- Jun 2011
- Location
- Tsukuba, Japan
- Posts
- 63
- Rep Power
- 0
OK. i apologise. Is the code inside the nested for loops correct? Can I do that?
- 06-03-2011, 06:12 PM #7
The code appears to be copying the value from one array to another. Yes you can do that if ....Can I do that?
both arrays are defined with the correct number of dimensions
indexes are in bounds
types of the two arrays are compatible
- 06-03-2011, 06:13 PM #8
Member
- Join Date
- Jun 2011
- Location
- Tsukuba, Japan
- Posts
- 63
- Rep Power
- 0
OK. I'll work on the indexes and get back to you.
- 06-08-2011, 11:27 AM #9
Member
- Join Date
- Jun 2011
- Location
- Tsukuba, Japan
- Posts
- 63
- Rep Power
- 0
Similar Threads
-
Help Array Index out of bounds exception
By star400040 in forum New To JavaReplies: 2Last Post: 12-10-2010, 10:24 PM -
[SOLVED] Array index out of bounds exception
By sruthi_2009 in forum New To JavaReplies: 5Last Post: 11-24-2010, 11:46 AM -
Array Index Out Of Bounds Exception
By manowar689 in forum New To JavaReplies: 3Last Post: 06-18-2010, 11:25 PM -
array Index out of Bounds exception== 0
By Allgorythm in forum New To JavaReplies: 6Last Post: 02-11-2010, 04:02 PM -
Array Index Out of Bounds Exception
By kool001 in forum New To JavaReplies: 1Last Post: 12-03-2009, 07:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks