그래서 내가 그를 만들기 위해 노력하고있어이 응용 프로그램이 사용하고 데이터베이스를 업데이트 할 필요하지만, 그것은 나에게이 오류주고 유지가 내 데이터베이스를 업데이트하는 기능을 여기NullPointerExcpetion 업데이트 데이터베이스
java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference
입니다 :
void insertdata(String id, int num) {
// ContentValues cv = new ContentValues();
// cv.put(Enwd, Integer.toString(num));
// Log.d(LOG_TAG,String.valueOf(cv));
// if (id == null){
// Log.d("ID IS","NULL");
// } else Log.d("ID IS","NOT NULL");
String thing = "update "+TABLE_NAME+" set "+col3+ "=num"+" where _id ="+id;
Log.d("CURS ",thing);
Cursor curs = mDataBase.rawQuery(thing,null);
curs.close();
// mDataBase.update(TABLE_NAME,cv,"_id= "+id,null);
}
은 내가 ContentValue를 사용하여 시도하고 그래서 나는 어쩌면 내가 잘못 뭘하는지 알아낼거야, rawQuery를 사용하는 거라고 생각은 작동하지 않았다 플러스 내가 할 수없는 것 튜토리얼을 찾기 위해 ContentValue 사용법을 철저히 설명합니다. 이것이 내 첫 번째 앱이며, 어떻게하는지 배우고 있습니다. 그것을 보내면, 어떤 도움이 될 것입니다!
편집 : 생각에 따라 좋아 내가 insertdata까지 변경 :
void insertdata(String id, int num) {
SQLiteDatabase db = getReadableDatabase();
// ContentValues cv = new ContentValues();
// cv.put(Enwd, Integer.toString(num));
// Log.d(LOG_TAG,String.valueOf(cv));
// if (id == null){
// Log.d("ID IS","NULL");
// } else Log.d("ID IS","NOT NULL");
String thing = "update "+TABLE_NAME+" set "+col3+ "=num"+" where _id ="+id;
Log.d("CURS ",thing);
Cursor curs = db.rawQuery(thing,null);
curs.close();
// mDataBase.update(TABLE_NAME,cv,"_id= "+id,null);
를하고 다른 오류를 받기 시작 :
android.database.sqlite.SQLiteException: no such column: num (code 1): , while compiling: update wordsdata set col3=num where _id =2
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(no such column: num (code 1): , while compiling: update wordsdata set col3=num where _id =2)
EDIT2 :
void insertyes(String id, int num) {
SQLiteDatabase db = getWritableDatabase();
Log.d("THE NUM",Integer.toString(num));
// ContentValues cv = new ContentValues();
// cv.put(Enwd, Integer.toString(num));
// Log.d(LOG_TAG,String.valueOf(cv));
// if (id == null){
// Log.d("ID IS","NULL");
// } else Log.d("ID IS","NOT NULL");
/* String thing = "update "+TABLE_NAME+" set "+Enyes+ "="+num +" where _id ="+id;
Log.d("CURS ",thing);
Cursor curs = db.rawQuery(thing,null);
curs.close();*/
ContentValues cv = new ContentValues();
Log.d(LOG_TAG, "--- Update table: ---");
cv.put(Enyes, num);
int updCount = db.update(TABLE_NAME, cv, "_id = "+id,null);
Log.d("THE UPDATED SHIT",Integer.toString(updCount));
}
이'mDataBase입니다 '설정? –
가능한 [NullPointerException이란 무엇이며 어떻게 수정합니까?] (http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it)) –
그것은 약간 혼란 스러워요, 나는 col3, 일명 _id는 2이지만, 특정 필드를 업데이트하려고합니다. 그러나 쿼리가 그렇게하지 않는 것 같습니다. 어리석은 질문에 대해 유감스럽게 생각합니다.) : @MikeM. – lua