我正在关注@JuanSánchez建议的answer,但我遇到了一个问题。
尝试将ClassCastException
对象(c)转换为android.database.Cursor
时,我的问题是CursorWrapper
。更具体地说,代码行为CursorWrapper cw = (CursorWrapper)c;
。
CursorWindow cursorWindow = null;
int cursorPosition = 0;
if (android.os.Build.VERSION.SDK_INT < 11) {
CursorWrapper cw = (CursorWrapper)c;
Class<?> cursorWrapper = CursorWrapper.class;
Field mCursor = null;
try {
mCursor = cursorWrapper.getDeclaredField("mCursor");
mCursor.setAccessible(true);
AbstractWindowedCursor abstractWindowedCursor = (AbstractWindowedCursor)mCursor.get(cw);
cursorWindow = abstractWindowedCursor.getWindow();
cursorPosition = abstractWindowedCursor.getPosition();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
任何帮助我都会非常感激。
答案 0 :(得分:0)
解决了这个问题。超级简单。
换掉以下几行。
交换 CursorWrapper cw = (CursorWrapper)cursor;
CursorWrapper cw = new CursorWrapper(cursor);