Question

I am following the answer suggested by @JuanSánchez but I have come across an issue.

My issue is a ClassCastException when trying to cast the android.database.Cursor object (c) to CursorWrapper. More specifically the line of code as so 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();
            }

        }

Any help I would be extremely grateful.

Was it helpful?

Solution

Worked it out. Super simple.

Swap out the following lines.

Swap CursorWrapper cw = (CursorWrapper)cursor;

For CursorWrapper cw = new CursorWrapper(cursor);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top