Ok, I’m quite stumped here. I’m getting an error, eclipse/android is saying that my app is crashing because a column does not exist in a table. The problem is, I’m not using the column id it’s quoting, and I can’t find any reason why it’s doing this.
In my DB create statement:
private static final String CREATE_HISTORY_TABLE=
" create table if not exists " + HISTORY_TABLE +
" (id integer primary key autoincrement," +
" DebtName text, Date date, Payment real )";
In my onCreate:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.paymenthistory_dialog);
Bundle extras = getIntent().getExtras();
String debtname = extras.getString(DbAdapter.KEY_DEBT);
String[] from = new String[]{ DbAdapter.KEY_HISTORY_DATE, DbAdapter.KEY_HISTORY_PAYMENT};
int[] to = new int[]{R.id.PAYMENTDATE, R.id.PAYMENTDATE};
ListView paymenthistory = (ListView)findViewById(R.id.paymenthistorylist);
DatabaseHelper db = new DatabaseHelper(this);
Cursor PaymentsCursor = db.getReadableDatabase().rawQuery("SELECT * FROM tblPaymentHistory WHERE DebtName = '"+debtname+"'", null);
---> SimpleCursorAdapter HistoryAdapter = new SimpleCursorAdapter(PaymentHistory.this, R.layout.paymenthistoryrow, PaymentsCursor, from, to);
paymenthistory.setAdapter(HistoryAdapter);
}
The line with the arrow is the one that has the error. I’ve opened the DB in an sqlite browser, and it has “id” as the column name, yet I consistently get the following error in eclipse when I test my activity:
11-18 00:26:40.775: E/AndroidRuntime(18419): Caused by: java.lang.IllegalArgumentException: column ‘_id’ does not exist
_idis a special column in SQLite. Normally it’s created automatically if you don’t create it.This error happens because
SimpleCursorAdapterneeds a column named_id.To fix this, you can either
Change your queries so that they are similar to:
SELECT DISTINCT id as _id …
Or recreate the table and rename
idto_id