DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

JsonModel load cursor erro

Open OptimistNot opened this issue 11 years ago • 3 comments

Hey! Still getting error with cursor in load() in JsonModel class solved with:

        if(cursor != null) {
            if(cursor.moveToFirst()){
                modelContainerAdapter.loadFromCursor(cursor, this);
                cursor.close();
            }
            cursor.close();
        }

instead of:

        if(cursor != null && cursor.moveToFirst()) {
            modelContainerAdapter.loadFromCursor(cursor, this);
            cursor.close();
        }

no clue what's going on...

OptimistNot avatar Aug 25 '15 14:08 OptimistNot

@OptimistNot it appears a Cursor is left open? or that the Cursor cannot moveToFirst(). Which is strange. I wonder how that could fail?

agrosner avatar Aug 26 '15 23:08 agrosner

Hmmm....found this today: http://stackoverflow.com/questions/30802132/do-i-need-to-close-a-cursor-if-movetofirst-is-false I suppose if cursor is not null but has no first to move the above condition (cursor != null && cursor.moveToFirst()) will fail...but you should close it anyway as it not null...no? In your load() method if query has no result it returns null? or something empty? Seems like empty but not null.

OptimistNot avatar Aug 27 '15 09:08 OptimistNot

fixed in 3.0 by a try...finally cursor.close() so that any cursor will be closed.

agrosner avatar Nov 29 '15 22:11 agrosner