int nameIndex = cursor.getColumnIndexOrThrow("name");
public int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query("mytable", null, null, null, null, null, null); if (cursor.moveToFirst()) { int index = cursor.getColumnIndexOrThrow(columnName); cursor.close(); return index; } else { cursor.close(); throw new IllegalArgumentException("Column does not exist"); } }This example creates a custom method in the MyDBAdapter class that queries a table and retrieves the index of a column specified by the columnName parameter. If the column does not exist, it throws an IllegalArgumentException. Package library: android.database