gpt4 book ai didi

android - Kotlin with Room and Dagger - 编译错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:44:47 24 4
gpt4 key购买 nike

我正在处理我的第一个 Android Kotlin 应用程序。我的第一个 Activity 是处理模拟数据后,我现在正尝试从数据库中获取数据,但代码无法编译。

Kotlin 代码:

@Dao
interface TagGroupDao {

@Query("select * from TagGroup")
fun getAll(): LiveData<List<TagGroup>>
}

这已生成此 java 代码:

public class TagGroupDao_Impl implements TagGroupDao {
private final RoomDatabase __db;

public TagGroupDao_Impl(RoomDatabase __db) {
this.__db = __db;
}

@Override
public LiveData<List<TagGroup>> getAll() {
final String _sql = "select * from TagGroup";
final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
return new ComputableLiveData<List<TagGroup>>() {
private Observer _observer;

@Override
protected List<TagGroup> compute() {
if (_observer == null) {
_observer = new Observer("TagGroup") {
@Override
public void onInvalidated(@NonNull Set<String> tables) {
invalidate();
}
};
__db.getInvalidationTracker().addWeakObserver(_observer);
}
final Cursor _cursor = __db.query(_statement);
try {
final int _cursorIndexOfId = _cursor.getColumnIndexOrThrow("Id");
final int _cursorIndexOfName = _cursor.getColumnIndexOrThrow("Name");
final List<TagGroup> _result = new ArrayList<TagGroup>(_cursor.getCount());
while(_cursor.moveToNext()) {
final TagGroup _item;
final long _tmpId;
_tmpId = _cursor.getLong(_cursorIndexOfId);
final String _tmpName;
_tmpName = _cursor.getString(_cursorIndexOfName);
_item = new TagGroup(_tmpId,_tmpName);
_result.add(_item);
}
return _result;
} finally {
_cursor.close();
}
}

@Override
protected void finalize() {
_statement.release();
}
}.getLiveData();
}
}

对 ComputableLiveData 的引用未解析。

e: TagGroupDao_Impl.java:3: error: cannot find symbol
e:

e: import android.arch.lifecycle.ComputableLiveData;
e: ^
e: symbol: class ComputableLiveData
e: location: package android.arch.lifecycle
e: java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing

最后,我的依赖项:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation "android.arch.persistence.room:runtime:1.0.0"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
implementation "android.arch.lifecycle:livedata-core:1.1.1"
implementation "android.arch.lifecycle:common-java8:1.0.0"
implementation 'com.google.dagger:dagger:2.13'
implementation "com.google.dagger:dagger:2.13"
implementation "com.google.dagger:dagger-android:2.13"
implementation "com.google.dagger:dagger-android-support:2.13"
kapt "android.arch.persistence.room:compiler:1.0.0"
kapt 'com.google.dagger:dagger-compiler:2.13'
kapt "com.google.dagger:dagger-android-processor:2.13"
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation 'junit:junit:4.12'
testImplementation "android.arch.persistence.room:testing:1.0.0"
testImplementation "android.arch.core:core-testing:1.1.1"
}

根据我设法收集到的关于 ComputableLiveData 的信息,它是一个不能直接使用的内部类。

如果我从 kotlin 代码中删除 LiveData<> 包装器,它会编译。

我在别处引用了 MutableLiveData<> 没有问题;我的 Activity 观察数据集并更新。

谁能指出我正确的方向?

最佳答案

更改此依赖项:

implementation "android.arch.lifecycle:livedata-core:1.1.1"

对此:

implementation "android.arch.lifecycle:livedata:1.1.1"

关于android - Kotlin with Room and Dagger - 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49769061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com