It could be a mess of different things. Could you post the error? How many times does it loop before the exception? You might want to do result.getCount() -1;i++ I haven't worked much with arrays and getting the number of elements back but in VB if you have 10 items it returns 10, but since arrays are 0 based when you use a counter to ref the position in the array you would need to make sure you only go to 9. If you go to the full count length (10) you get an index out of bounds exception.
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Honest Sent: Sunday, February 27, 2011 7:56 PM To: Android Developers Subject: [android-developers] exception in getting data from cursor(database) hello, i am retrieving Cursor from database but when i am trying to get data from cursor using colIndex. i am getting exception. can some one tell me what is wrong in it. the following is code i am using . it is giving exception at the sentence data[i]=result.getString(colIndex); /*code*/ db=new DBAdapter(this); db.open(); Cursor result=db.getAllNames(); Log.e("column:",":"+ result.getColumnCount()); String data[]=new String[result.getCount()]; for(int i=0;i<result.getCount();i++) { Log.e("column:",":"+ result.getColumnCount()); if(data[i]==null) Log.e("null", "null"); data[i]=new String(); int colIndex=result.getColumnIndexOrThrow("name"); Log.e("colIndex", ":"+colIndex); data[i]=result.getString(colIndex); //data[i]=temp; // Log.e("temp:", temp); result.moveToNext(); hope to hear soon. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

