Cursor.getType()API< 11个问题

时间:2013-11-15 11:03:34

标签: android android-sqlite android-cursor

我正在关注@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();
            }

        }

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

1 个答案:

答案 0 :(得分:0)

解决了这个问题。超级简单。

换掉以下几行。

交换 CursorWrapper cw = (CursorWrapper)cursor;

CursorWrapper cw = new CursorWrapper(cursor);