I'm using Parse.com library and I want to query from local datastore if user lost access to internet (query on pinned items from previous app usage). Problem is that if use offline query it will not return List<Object>
but weird AbstractList
and I don't know how to convert it to ArrayList.
Anyone had this issue?
API call:
fun getFilteredObjects(c: Context, searchQuery: String?, filteredObjectsCallback: (ArrayList<ParseObject>?, ParseException?) -> Unit){
val q = ParseQuery.getQuery<ParseObject>(OBJECT_CLASS)
if (!isOnline(c)) q.fromLocalDatastore()
if (searchQuery.isNullOrEmpty()){
q.limit = 10
} else {
q.whereMatches(OBJECT_NAME, searchQuery, "i")
}
q.findInBackground { objectList, err ->
filteredObjectsCallback(objectList as ArrayList<ParseObject>?, err)
}
}
Error line: filteredObjectsCallback(objectList as ArrayList<ParseObject>?, err)
Error:
java.lang.ClassCastException: java.util.AbstractList$SubAbstractListRandomAccess cannot be cast to java.util.ArrayList
Your cast is invalid because types are not convertible: objectList
is of type AbstractList
and that cannot be hard casted to ArrayList
like that.
Instead, use Arrays.asList(objectList)
, I think it has its own implementation and translates the abstract list.