[英]Flowable in room
@Database(entities = {User.class}, version = 2, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
public abstract userDao userDao();
}
Pojo 用戶類
@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
public interface userDao {
@Query("SELECT * FROM User WHERE id = :id")
Flowable<User> get(int id);
@Insert
Completable insert(User user);
}
依賴關系
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: 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>)
我試圖弄清楚如何在房間里使用 rxjava,我按照示例進行操作,但它拋出了一個錯誤,有什么問題? 可完成的工作正常
我不知道您為什么將ianhanniballake的答案標記為正確的答案。
依賴“ androidx.room:room-ktx:2.2.3 ”與RxJava無關。
我的情況我通過添加這個依賴項解決了這個問題
implementation "androidx.room:room-rxjava2:2.2.3"
插入我的舊版本:
implementation 'android.arch.persistence.room:rxjava2:1.1.1'
希望這會有所幫助
由於每房聲明依賴文件,你需要的依賴關系room-ktx
使用協同程序,並與, Flowable
:
implementation "androidx.room:room-ktx:2.2.3"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.