I am trying to update the value of a particular column in my table. I already have a ContentProvder set up. I am receiving an error and I don't know how to fix it. I have searched for help on-line and none of them seem to update based on the unique-id. Here is my code..
@Override
public int update (Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
int uriType = NewsContract.sURI_MATCHER.match(uri);
SQLiteDatabase db = dictionaryHelper.getWritableDatabase();
int rowsUpdated = 0;
String id = null;
switch (uriType)
{case DictionaryContract.RECENT:
rowsUpdated = db.update(DictionaryContract.DictionaryDataContract.RECENT_TABLE_NAME,
values,
selection,
selectionArgs);
break;
case DictionaryContract.RECENT_ID:
id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
rowsUpdated = db.update(DictionaryContract.DictionaryDataContract.RECENT_TABLE_NAME,
values,
DictionaryContract.DictionaryDataContract._ID + "=" + id,
null);
} else {
rowsUpdated = db.update(DictionaryContract.DictionaryDataContract.RECENT_TABLE_NAME,
values,
DictionaryContract.DictionaryDataContract._ID + "=" + id
+ " and "
+ selection, selectionArgs);
}
break;
default:
throw new IllegalArgumentException("Unknown URI" + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return rowsUpdated;
}
And this is how I am calling the update method of the ContentProvider:
private boolean UpdateRecentTable()
{
cursor.moveToLast();
Long id = cursor.getLong(cursor.getColumnIndex(DictionaryContract.DictionaryDataContract._ID));
Log.i("Update", " " + id);
String filter = DictionaryContract.DictionaryDataContract._ID + "=" + id;
ContentValues args = new ContentValues();
args.put(DictionaryContract.DictionaryDataContract.REC_FAVORITED, 1);
dResolver.update(DictionaryContract.CONTENT_URI_RECENT, args, filter, null);
return true;
}
Error:
03-21 04:05:36.823 18326-18673/com.example.clinton.light E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.example.clinton.light, PID: 18326 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:309) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.IllegalArgumentException: Unknown URIcontent://com.example.clinton.light.provider.dictionary/recents at com.example.clinton.light.database.DictionaryContentProvider.update(DictionaryContentProvider.java:216) at android.content.ContentProvider$Transport.update(ContentProvider.java:355) at android.content.ContentResolver.update(ContentResolver.java:1362) at com.example.clinton.light.dictionary_main.StoreFavWord.UpdateRecentTable(StoreFavWord.java:72) at com.example.clinton.light.dictionary_main.StoreFavWord.doInBackground(StoreFavWord.java:41) at com.example.clinton.light.dictionary_main.StoreFavWord.doInBackground(StoreFavWord.java:18) at android.os.AsyncTask$2.call(AsyncTask.java:295) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) 03-21 04:05:37.271 18326-18352/com.example.clinton.light E/Surface: getSlotFromBufferLocked: unknown buffer: 0xe0c79230
Any help will be appreciated. Please NB: I do not have enough points to mark your answer as correct. I will nevertheless thank you.
Aucun commentaire:
Enregistrer un commentaire