Android Room Persistance Library-SQlite:调试gradle错误

时间:2019-07-11 23:01:32

标签: android sqlite android-sqlite android-room

只是设置了一个Sqlite数据库,做了我的第一个成功的插入操作,当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);

1 个答案:

答案 0 :(得分:1)

您将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