I recently won a Motorola Droid phone in the “claw event” promotion held by Verizon. That being said I wanted to take a stab at some development on it. I was trying to use the SimpleCursorAdaptor method to bind results from sqlite to a listview.. and it just wasn’t happening.
To create the database I had a line like this:
private static final String DATABASE_CREATE =
"create table decks (id integer primary key autoincrement, "
+ "name text not null);";
My application would throw an exception and I had no idea why until I wrote a simple debug method. It’s the equivalent of “alert();” in javascript.
public void createAlert(String message){
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Message");
alertDialog.setMessage(message);
alertDialog.setButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
return; }
});
alertDialog.show();
}
I simply threw my code in a java try-catch and received the error: “column _id does not exist.” Did you catch that? I didn’t declare my column name with an underscore.
I guess it is always good to read the documentation.
Adapter that exposes data from a
Cursorto aListViewwidget. The Cursor must include a column named “_id” or this class will not work.
Now why would I post this lame crap? Because after googling the problem… it seems that a lot of beginners are running into this issue.
Tags: android, droid, java, mobile development, motorola droid
Never too late for a comment! Guess you can’t get fancy and go naming your own id columns when using SimpleCursorAdapter. Tip is greatly appreciated..