Hi to All, It would be kind if anyone could let me know , why i am getting this exception in the following code : ----------- Vector v = new Vector(); NameData data = null; while(rs.next()){ data = new NameData(rs.getString(1),rs.getInt (2));// this is name & nameid from NAME table. v.addElement(data); } int iSize = v.size();// here v.size is 1 String[][] names = new String[iSize][iSize]; for(int i=0; i < iSize; i++){ data = (NameData)v.get(x); names[i][0] = data.getName();// this is 'MyName' (The below lines throws Array Index OutOf Bounds Exception) names[i][1] = Integer.toString(data.getNameId ()); // this is 11899 } -------------------- I am not really clear why this exception is coming up when the size is 1. When the size is more than 1 for example 10 then this exception is not thrown. Any replies will be appreciated. Thanks, Regards John
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Hi Lijoy, Try this:
Cheers
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
Remember that array indices start at zero. If the size of the array is 1 then 0 is the only valid index. Any other value is out of bounds. In other words, when you use 1 as an index, the exception is thrown.