Populate listview with data from Cursor?
<p>I'm having a bit of trouble figuring out how to bind data from sqlite to a listview.<br/>
Here my entire code and I'd be very thankful for some help or tips. <br/>
The trouble here is that i'm getting the following exception: <br/>
Illegalargumentexception: the column "_id" does not exist, when calling GetCursor in SimpleCursorAdapter.</p>

<p>main.xml <br/></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"&gt;    
   &lt;ListView
      android:id="@android:id/android:list"
      android:layout_width="fill_parent"
     android:layout_height="wrap_content" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>item_list.xml<br/></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical"&gt;
&lt;TextView
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="24dp"
    android:padding="6dp" /&gt;
&lt;TextView
    android:id="@+id/time"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="18dp"
    android:padding="1dp" /&gt;
&lt;TextView
    android:id="@+id/date"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="18dp"
    android:padding="4dp"
    android:gravity="right" /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>Class implementing SQLite<br/></p>

<pre><code>import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;

public class DataHelper {

private static final String DATABASE_NAME = "example.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "table1";      

private Context context;
private SQLiteDatabase db;
private SQLiteStatement insertStmt;
private Cursor cursor;

public DataHelper(Context context) {
    this.context = context;
    OpenHelper openHelper = new OpenHelper(this.context);
    this.db = openHelper.getWritableDatabase();
}

public long insert(String name, String time, String date) {
    insertStmt = db.compileStatement("insert into table1 values(?,?,?)");       
    this.insertStmt.bindString(1, name);
    this.insertStmt.bindString(2, time);
    this.insertStmt.bindString(3, date);
    return this.insertStmt.executeInsert(); 
}

public void deleteAll() {
    this.db.delete(TABLE_NAME, null, null);
}

public Cursor GetCursor() {
    cursor = this.db.query(TABLE_NAME, new String[] { "_id", "name", "time", "date" }, null, null, null, null, "date desc");

    return cursor;      
}

private static class OpenHelper extends SQLiteOpenHelper {

    OpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + TABLE_NAME + "( _id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, time TEXT, date TEXT);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w("Example",
                "Upgrading database, this will drop tables and recreate.");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    }
    }
}
</code></pre>

<p>onCreate class<br/></p>

<pre><code>import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;

public class SqlTest extends ListActivity {

private DataHelper dh;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Date now = new Date();
    String time = now.getHours() + ":" + now.getMinutes();
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    String date = df.format(now);

    this.dh = new DataHelper(this);
    this.dh.deleteAll();
    this.dh.insert("Porky Pig", time, date);
    this.dh.insert("Foghorn Leghorn", time, date);
    this.dh.insert("Yosemite Sam", time, date);
    this.dh.insert("SD", time, date);

    String[] columns = new String[] { "_id", "name", "time", "date" };
    int[] to = new int[] {R.id.name, R.id.time, R.id.date};

    SimpleCursorAdapter mAdap = new SimpleCursorAdapter(this, R.layout.main, this.dh.GetCursor(), columns, to);

    this.setListAdapter(mAdap);
}
}
</code></pre>
