java-不兼容的类型:MainActivity无法转换为LifecycleOwner
作者:互联网
MainActivity cannot be converted to LifecycleOwner
我以LiveCycle Owner的身份使用它,但是它被拒绝了,您在图片中看到了一个错误.
我在Api 25上工作,我这个问题可能与这个版本有关
这是关于我的SDK的信息
compileSdkVersion 25
buildToolsVersion '25.0.2'
这是我的代码:
private void retrieveTasks() {
Log.d(TAG, "Actively retrieving the tasks from the DataBase");
// Extract all this logic outside the Executor and remove the Executor
// Fix compile issue by wrapping the return type with LiveData
LiveData<List<TaskEntry>> tasks = mDb.taskDao().loadAllTasks();
// Observe tasks and move the logic from runOnUiThread to onChanged
tasks.observe(this, new Observer<List<TaskEntry>>() {
@Override
public void onChanged(@Nullable List<TaskEntry> taskEntries) {
Log.d(TAG, "Receiving database update from LiveData");
mAdapter.setTasks(taskEntries);
}
});
}
我将LiveData依赖项放在了Gradle中
compile "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
如果有人知道问题的原因,请告诉我
解决方法:
如您所见here,LifecycleOwner已添加到支持库26.1.0中.解决问题的最简单方法是升级支持库版本.
标签:android-room,android-gradle,android-livedata,java,android 来源: https://codeday.me/bug/20191108/2010100.html