New phone, New Development, New Instructions

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 Cursor to a ListView widget. 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.

Continue reading » · Written on: 12-01-09 · 1 Comment »

One Response to “New phone, New Development, New Instructions”

  1. Jay wrote:

    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..

    May 13th, 2010 at 12:07 am

Leave a Reply