2016-12-14 180 views
-4

我試圖用sqlitedatabase,所以在我更新類我得到一個錯誤,這是這裏的PIC http://prntscr.com/djbe3i在SQLiteDatabase

這裏來更新我的列表視圖的信息更新的信息是該dbhelper方法的代碼:

public int updateInformation(String old_name, String new_name,String old_hours, String new_hours, String old_department,String new_department,SQLiteDatabase sqLiteDatabase) { 

    ContentValues contentValues = new ContentValues(); 
    contentValues.put(UserContract.NewUserInfo.Name,new_name); 
    contentValues.put(UserContract.NewUserInfo.RenderedHours,new_hours); 
    contentValues.put(UserContract.NewUserInfo.Department,new_department); 

    String selection = UserContract.NewUserInfo.Name + " LIKE ?"; 
    String[] selection_args = {old_name}; 
    int count = sqLiteDatabase.update(UserContract.NewUserInfo.TABLE_NAME,contentValues,selection,selection_args); 
    return count; 

} 

更新類代碼:

public void updateContact(View view) { 

    userDBHelper = new UserDBHelper(getApplicationContext()); 
    sqLiteDatabase = userDBHelper.getWritableDatabase(); 
    String name,hours,department; 

    name = new_name.getText().toString(); 
    hours = new_hours.getText().toString(); 
    department = new_department.getText().toString(); 
int count = userDBHelper.updateInformation(search_id,NewName,NewHours,NewDepartment,sqLiteDatabase); 

} 
} 

編輯:我改變了代碼爲:

public void updateContact(View view) { 

    userDBHelper = new UserDBHelper(getApplicationContext()); 
    sqLiteDatabase = userDBHelper.getWritableDatabase(); 
    String name,hours,department; 

    name = new_name.getText().toString(); 
    hours = new_hours.getText().toString(); 
    department = new_department.getText().toString(); 
    int count = userDBHelper.updateInformation(search,name,hours,department,sqLiteDatabase); 

} 

我仍然收到錯誤,我不明白。

2ND編輯:我明白了,現在好了,我只輸入了錯誤的字符串,我需要的更新接觸我取代了代碼到參數:

int count = userDBHelper.updateInformation(search_id,name,hours,department,sqLiteDatabase); 

DBHelper.updateInformation代碼:

public int updateInformation(String old_name, String new_name, String new_hours,String new_department,SQLiteDatabase sqLiteDatabase) 
+1

計算你的參數,你應該能夠弄清楚這一點。 IDE告訴你到底發生了什麼問題。 – gpgekko

+0

你的兩個參數:'String old_department','String new_department'丟失 – Meet

+0

而且你添加了edittext函數而不是字符串檢查函數。其實這個函數有七個參數,但是你只傳遞了五個參數 – Vishwa

回答

0

我得到了,現在我的參數不匹配,我改變了代碼轉換成固定它:

public int updateInformation(String old_name, String new_name, String new_hours,String new_department,SQLiteDatabase sqLiteDatabase) 

然後改變更新類中的代碼:

int count = userDBHelper.updateInformation(search_id,name,hours,department,sqLiteDatabase);