Hi everyone. I'm trying to populate a spinner from a database. I've been debugging it slowly to see what's going wrong.
I have created my own database which is packaged in the asset directory and moved over to /data/data/my.app/databases/myappdata when the application is launched. I've written a database adapter class following the notepad tutorial examples. I'm using very simple queries that just return all of the info from a set table at the moment. public Cursor fetchAllUnits() { Log.i(TAG, "Fetched all units."); return mDb.query(DATABASE_UNITS_TABLE, new String[] {KEY_ROWID, KEY_NAME}, null, null, null, null, null); } This part seems to be working perfectly, as I'm getting a size in the cursor when it's returned: Cursor c = mDbHelper.fetchAllUnits(); Log.i(TAG, "c.count = " + c.getCount()); Log.i(TAG, "c.getColumnCount = " + c.getColumnCount()); startManagingCursor(c); Gives me this: I/Conversion( 732): c.count = 8 I/Conversion( 732): c.getColumnCount = 2 After this I decided to implement a for loop just to see if I could display all the cursor information before I actually try to use it somewhere. Here's my loop: for(int i=0; i < c.getCount(); i++) { int col = c.getColumnIndexOrThrow (ConversionDbAdapter.KEY_NAME); Log.i(TAG, "col = " + col); try { c.getString(col); String name = c.getString(col); } catch(Exception e) { Log.i(TAG, "Error = " + e); } //Log.i(TAG, "getString = " + c.getString(col)); Log.i(TAG, "i = " + i); c.moveToNext(); } The getString is what seems to be causing me the issue: I/Conversion( 732): col = 1 I/Conversion( 732): Error = android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 8 I can't understand why it's saying an index of -1 was requested. I print the value of col directly above, and it's 1. It does it even if I replace col with a literal 1. Now I've caught the exception the rest of the loop goes on to execute normally: I/Conversion( 732): i = 0 I/Conversion( 732): col = 1 I/Conversion( 732): i = 1 I/Conversion( 732): col = 1 I/Conversion( 732): i = 2 I/Conversion( 732): col = 1 I/Conversion( 732): i = 3 I/Conversion( 732): col = 1 I/Conversion( 732): i = 4 I/Conversion( 732): col = 1 I/Conversion( 732): i = 5 I/Conversion( 732): col = 1 I/Conversion( 732): i = 6 I/Conversion( 732): col = 1 I/Conversion( 732): i = 7 Can anyone help me with this at all? It's driving me absolutely crazy. All the help I've found online seems to be based on an old version of the SDK, and it's so frustrating that I'm starting to lose track of what I'm even trying to do. Please help. Stuart. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---