Db to ListView error
I am trying to create a list view from the database. this is the code
List Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox);
DBAdapter db = new DBAdapter(InboxActivity.this);
db.open();
long userID = Long.parseLong(MessagingApplication.getUserID());
Cursor inbox = db.readInbox(userID);
startManagingCursor(inbox);
String[] mails = new String[] { DBAdapter.KEY_NAME };
int[] to = new int[] { R.id.name };
SimpleCursorAdapter i开发者_开发知识库nboxmail = new SimpleCursorAdapter(this,
R.layout.inbox_list, inbox, mails, to);
setListAdapter(inboxmail);
db.close();
}
This is the code that fetches data from the DB
public Cursor readInbox(long toId) throws SQLException {
return db.query(TABLE_MAILS, new String[] { ID, KEY_FROM, KEY_TO,
KEY_SUB, KEY_BODY, KEY_DATETIME, KEY_READ }, KEY_TO + "="
+ toId, null, null, null, null, null);
}
My DB
private static final String CREATE_MAILS = "CREATE TABLE mails (id INTEGER PRIMARY KEY AUTOINCREMENT, pid INTEGER DEFAULT '0', from_id INTEGER, to_id INTEGER, subject TEXT, body TEXT, datetime TEXT, read INTEGER);";
Error:
http://variable3.com/files/screenshots/2010-12-29_1136.png
The column "_id" does not exist. Notice the underline in front of id. Please have a look at your log, it's written there.
精彩评论