0

我正在关注@JuanSánchez 建议的答案,但我遇到了一个问题。

我的问题是ClassCastException尝试将android.database.Cursor对象 (c) 转换为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();
            }

        }

任何帮助我都会非常感激。

4

1 回答 1

0

解决了。超级简单。

交换以下行。

交换 CursorWrapper cw = (CursorWrapper)cursor;

为了 CursorWrapper cw = new CursorWrapper(cursor);

于 2013-11-15T12:16:45.983 回答