Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flowable in room

@Database(entities = {User.class}, version = 2, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
    public abstract userDao userDao();
}

Pojo user class

@Entity
    public class User {
        @PrimaryKey(autoGenerate = true)
        private int id;

        public User(){
        }



        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }
    }

Dao

@Dao
public interface userDao {
            @Query("SELECT * FROM User WHERE id = :id")
            Flowable<User> get(int id);
            @Insert
            Completable insert(User user);
        }

Dependencies

implementation "androidx.room:room-runtime:2.2.3"
annotationProcessor "androidx.room:room-compiler:2.2.3"
implementation "android.arch.persistence.room:rxjava2:1.1.1"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation "io.reactivex.rxjava2:rxjava:2.2.14"

Error

error: no suitable method found for createFlowable(RoomDatabase,boolean,String[],<anonymous Callable<User>>)
method RxRoom.createFlowable(RoomDatabase,String...) is not applicable
(varargs mismatch; boolean cannot be converted to String)
method RxRoom.<T>createFlowable(RoomDatabase,String[],Callable<T>) is not applicable
(cannot infer type-variable(s) T
(actual and formal argument lists differ in length))
where T is a type-variable:
T extends Object declared in method <T>createFlowable(RoomDatabase,String[],Callable<T>)

I'm trying to figure out how to work with rxjava in the room, I follow the examples, but it throws an error, what is the problem? Completable works fine

like image 453
ikiton Avatar asked Nov 17 '25 08:11

ikiton


2 Answers

I have no idea why you marked ianhanniballake's answer as a correct one.
Dependency "androidx.room:room-ktx:2.2.3" has nothing to do with RxJava.
I my case I fixed the problem by adding this dependency

implementation "androidx.room:room-rxjava2:2.2.3"

insted of my old one:

implementation 'android.arch.persistence.room:rxjava2:1.1.1' 

hope this will help

like image 138
Waldmann Avatar answered Nov 18 '25 20:11

Waldmann


As per the Room Declaring Dependencies documentation, you need a dependency on room-ktx to use Coroutines and, with that, Flowable:

implementation "androidx.room:room-ktx:2.2.3"
like image 27
ianhanniballake Avatar answered Nov 18 '25 21:11

ianhanniballake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!