| Author |
matrix array
|
dejie lin
Ranch Hand
Joined: Jan 29, 2003
Posts: 31
|
|
hi all, i have defined a class "matrix" by my self, i wanna have an array of matrix, the code is in the following: .... matrix[][] m=new matrix[20][15]; for(int i=0;i<20;i++) for(int j=0;j<20;j++) m[i][j] = new matrix(); .... class matrix { public int type; public int NodeNo; public matrix() { type=0; NodeNo =0; } void settype(int t) { type =t; } void setNodeNo(int n) { NodeNo =n; } } Problem : there's no compiling error, but there will be arrayIndexOutOfBoundsException .... Anybody can help me? thanks dejie
|
 |
Ashish Hareet
Ranch Hand
Joined: Jul 14, 2001
Posts: 375
|
|
Hi Dejie, j will max out at 14 so j < 20 is gonna throw an exception, it should read j < 15. A better approach would be - I don't think I have got this wrong, but do check, no JVM on this machine. HTH Ashish Hareet
|
<a href="http://www.irixtech.com/dynamic-quiz/java/scjp/all" target="_blank" rel="nofollow">SCJP 5.0 & SCJP 6.0 Topics based Mock Exams</a> <a href="http://www.irixtech.com/category/java/scjp-quiz" target="_blank" rel="nofollow">SCJP 5.0 & SCJP 6.0 Mock Exams</a><br /><a href="http://www.irixtech.com/forums/forums" target="_blank" rel="nofollow">iRix Forums for SCJP</a> <a href="http://www.irixtech.com/" target="_blank" rel="nofollow">iRix Technologies</a>
|
 |
 |
|
|
subject: matrix array
|
|
|