将 Android Room Database 与 RXJava2 一起使用时找不到符号 class EmptyResultSetException
Cannot find symbol class EmptyResultSetException when using Android Room Database with RXJava2
我正在尝试将 RXJava2 与 Room 数据库 一起使用。我使用 Single Observable 来获取我的对象列表。但是每次我得到这个错误
cannot find symbol class EmptyResultSetException
我正在使用本教程ANDROID ROOM PERSISTENT AND RXJAVA2
我之前在没有 RXJava 的情况下使用 AsyncTask 并且它有效所以我想将它与 RXJava[ 一起使用=38=]
这是我的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "apit.net.sa.simpleusingroom"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v13:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.jakewharton:butterknife:8.5.1'
//ROOM database
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
//RXJava2
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
//RXjava with room
implementation 'android.arch.persistence.room:rxjava2:1.0.0-alpha1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
道Class
@Query("SELECT * FROM UserEntity")
Single<List<UserEntity>> getUsersSingle();
我的活动
DatabaseSingInstance.getInstance(this)
.getOurDatabase()
.userDAO()
.getUsersSingle()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableSingleObserver<List<UserEntity>>() {
@Override
public void onSuccess(final List<UserEntity> userEntities) {
adapter = new UserAdapter(userEntities, MainActivity.this, new UserAdapter.OnLongClickListner() {
@Override
public void onClick(int position) {
showPopupWindow(userEntities,position);
}
});
myRec.setAdapter(adapter);
}
@Override
public void onError(Throwable e) {
Log.e("error"," "+e.getMessage());
}
});
我按照这个解决了问题
我刚刚将 room_version 更改为 1.1.0 。
顺便说一句,我正在等待任何人能解释这个错误或只是解释为什么会发生。
我正在尝试将 RXJava2 与 Room 数据库 一起使用。我使用 Single Observable 来获取我的对象列表。但是每次我得到这个错误
cannot find symbol class EmptyResultSetException
我正在使用本教程ANDROID ROOM PERSISTENT AND RXJAVA2
我之前在没有 RXJava 的情况下使用 AsyncTask 并且它有效所以我想将它与 RXJava[ 一起使用=38=]
这是我的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "apit.net.sa.simpleusingroom"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v13:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.jakewharton:butterknife:8.5.1'
//ROOM database
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
//RXJava2
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
//RXjava with room
implementation 'android.arch.persistence.room:rxjava2:1.0.0-alpha1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
道Class
@Query("SELECT * FROM UserEntity")
Single<List<UserEntity>> getUsersSingle();
我的活动
DatabaseSingInstance.getInstance(this)
.getOurDatabase()
.userDAO()
.getUsersSingle()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableSingleObserver<List<UserEntity>>() {
@Override
public void onSuccess(final List<UserEntity> userEntities) {
adapter = new UserAdapter(userEntities, MainActivity.this, new UserAdapter.OnLongClickListner() {
@Override
public void onClick(int position) {
showPopupWindow(userEntities,position);
}
});
myRec.setAdapter(adapter);
}
@Override
public void onError(Throwable e) {
Log.e("error"," "+e.getMessage());
}
});
我按照这个解决了问题
我刚刚将 room_version 更改为 1.1.0 。 顺便说一句,我正在等待任何人能解释这个错误或只是解释为什么会发生。