Удалить Id , ContentResolver ???

Рейтинг: 0Ответов: 1Опубликовано: 24.01.2015

пытаюсь удалить из database id ...Как написать Правильно Код ??

public boolean onContextItemSelected(MenuItem item) {
        // return super.onContextItemSelected(item);
        Log.d(TAG, "long item select");
        Log.d(TAG, "1");

        switch (item.getItemId()) {
        case R.id.Favorite2:

            AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
            .getMenuInfo();
           long id = info.id;
        //  dbHandler.delete(id);
          Cursor cursor3 = getActivity().getContentResolver().query(
                    Contract.Favorite.CONTENT_URI, null,
                    Contract.Favorite._ID + "=" + id, null, null);

            if (cursor3 != null) {
                cursor3.moveToNext();
            //ContentResolver cr = getActivity().getContentResolver();
            ((ContentResolver) cursor3).delete(Contract.Favorite.CONTENT_URI,Contract.Favorite._ID + "=" + id, null);

            }
    return true;
        }

        return super.onContextItemSelected(item);
    }

ERROR : java.lang.ClassCastException: android.content.ContentResolver$CursorWrapperInner cannot be cast to android.content.ContentResolver

Ответы

▲ 1Принят

java.lang.ClassCastException: android.content.ContentResolver$CursorWrapperInner cannot be cast to android.content.ContentResolver

Дословный перевод:

java.lang.ClassCastException: android.content.ContentResolver$CursorWrapperInner не может быть приведен к android.content.ContentResolver

На какой строчке ошибка? на этой?

((ContentResolver)cursor3).delete(Contract.Favorite.CONTENT_URI,Contract.Favorite._ID + "=" + id, null);

А с чего вы вообще взяли, что Cursor cursor3 может быть приведен к типу ContentResolver? Где вы видели, что один наследуется от другого?