android - Android Room Persistance Library - SQlite:调试 gradle 错误
问题描述
刚刚设置了一个Sqlite db,我第一次成功插入,试图在代码中进行更新查询,突然android无法编译。收到此错误:
Gradle may disable incremental compilation as the following annotation processors are not incremental: room-compiler-2.1.0.jar (androidx.room:room- compiler:2.1.0), lifecycle-compiler-2.0.0.jar (androidx.lifecycle:lifecycle-compiler:2.0.0).
Consider setting the experimental feature flag android.enableSeparateAnnotationProcessing=true in the gradle.properties file to run annotation processing in a separate task and make compilation incremental.
C:\app\src\main\java\com\example\persistence\repositories\NoteRepository.java:74: error: method update in interface NoteDao cannot be applied to given types;
noteDao.update(notes[0]);
^
required: int,int
found: Note
存储库中与此方法相关的错误:
private static class UpdateNoteAsyncTask extends AsyncTask<Note, Void, Void>{
private NoteDao noteDao;
private UpdateNoteAsyncTask(NoteDao noteDao){
this.noteDao = noteDao;
}
@Override
protected Void doInBackground(Note... notes) {
noteDao.update(notes[0]);
return null;
}
}
数据访问类:
@Dao
public interface NoteDao {
@Insert
void insert(Note note);
@Query("UPDATE note_table SET distortions= :distortions WHERE cbtId= :cbtId")
void update(int cbtId, int distortions);
@Delete
void delete(Note note);
解决方案
您已update
定义为:
@Query("UPDATE note_table SET distortions= :distortions WHERE cbtId= :cbtId")
void update(int cbtId, int distortions);
所以你应该像这样使用它:
update(int cbtId, int distortions)
当你像这样使用它时:
noteDao.update(notes[0]);
Gradle 期待两个参数。在这里它说它找到了 Note 对象(来自你的论点)。
required: int,int
found: Note
推荐阅读
- javascript - 单个 HTML 文件中的多个 HTML 文件的选项卡式视图
- javascript - 将表情符号保存到 Node JS 中的文本文件
- xml - XML 到平面文件
- java - 如何在 Java 中有效地进行泛型转换
- javascript - 防止用户在 Datepicker 文本框中输入无效的日期格式而不禁用它
- regex - perl中与“(”匹配的正则表达式
- c# - 202 访问 wcf 时接受
- react-native - 如何在物理Android手机中本地安装反应本机应用程序?
- powershell - 为删除从今天起超过一个月的 Exchange 共享邮箱电子邮件执行 Powershell
- azure-devops - 如何在 XML 策略文件中将 Azure API 后端设置为 Azure 资源?