2010-12-29 3 views
0

데이터베이스에서 목록보기를 만들려고합니다. 이 코드입니다Db to ListView 오류

목록 활동

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 inboxmail = new SimpleCursorAdapter(this, 
    R.layout.inbox_list, inbox, mails, to); 

    setListAdapter(inboxmail); 

    db.close(); 
} 

이것은 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); 
} 

내 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);"; 

오류 :

alt text

http://variable3.com/files/screenshots/2010-12-29_1136.png

답변

2

열 "_id"존재하지 않습니다. 이드 앞에 밑줄이 있음을 확인하십시오. 로그에 기록하십시오.

+0

내 ID 열은 ID가 아닙니다. _ID 아니요. 코드에서 _id를 사용했습니다. 어디에서 가져 오는 이해가 안되니? –

+1

필수 항목입니다. 어댑터가 필요합니다. "id를 _id ...로 선택"하거나 열 이름을 바꿉니다. –

+0

확실히 무시할 수 있어야합니다. –