I am trying to select data from the table by id . But I get the error:

java.lang.IllegalStateException: Illegal State: Object is no longer valid to operate on. Was it deleted by another thread?

Here is the database request code

 RealmQuery<Exercise> query = realm.where(Exercise.class); for(Day d : dayList) { RealmResults<Exercise> results = query.equalTo("exercise_id", d.getExercise_id()).findAllAsync(); exercises.addAll(results); } 

    1 answer 1

    findAllAsync() searches asynchronously and the data on the next line will not be ready yet.

    You need to do findAll() method or the asynchronous request, hang the listener on the results and when it is called when the database request is completed add data