【发布时间】:2022-01-02 15:24:36
【问题描述】:
错误:不确定如何处理查询方法的返回类型 重建项目后 DbDao 类中出现异常错误。 在那之前,一切都很好,在那个类中没有做任何事情,也没有做任何与那个库有关的事情,但是突然之间它开始在生成的 java 文件中抛出错误
错误: D:\workspace\workspace\Android studio\CorralApp\ProjectCoral\app\build\tmp\kapt3\stubs\debug\com\mmscode\coralproject\db\DbDao.java:21:错误:不确定如何处理查询方法的返回类型(java.lang.Object)。 DELETE 查询方法必须返回 void 或 int(删除的行数)。 公共抽象 java.lang.Object deleteUser(@org.jetbrains.annotations.NotNull() ^
例如,如果我删除函数 deleteUser,此错误将显示在其他函数上
代码:
package com.mmscode.coralproject.db
import androidx.lifecycle.LiveData
import androidx.room.*
@Dao
abstract class DbDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertUserData(user: DbUser)
@Query("DELETE FROM DbUser")
abstract suspend fun deleteUser()
@Query("SELECT * FROM DbUser")
abstract suspend fun getUser(): DbUser?
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertDailySchedule(list: List<DbSchedule>)
@Query("SELECT * FROM DbSchedule where scheduleStatusName NOT LIKE 'ENDED' ORDER BY eventTime")
abstract fun getDailySchedule(): LiveData<List<DbSchedule>>?
@Query("SELECT * FROM DbSchedule where scheduleStatusName NOT LIKE 'ENDED' AND date(substr(dateFrom,7,4)|| '-' ||substr(dateFrom,1,2)|| '-'||substr(dateFrom,4,2)) > date(:date,'start of month', '-1 month', '-10 day')")
abstract suspend fun getDailySchedule2(date: String): List<DbSchedule>
@Query("SELECT * FROM DbSchedule where scheduleStatusName NOT LIKE 'ENDED' ORDER BY eventTime")
abstract suspend fun getDailySchedule3(): List<DbSchedule>
@Query("SELECT * FROM DbSchedule where scheduleStatusName NOT LIKE 'ENDED' and date(substr(dateFrom,7,4)|| '-' ||substr(dateFrom,1,2)|| '-'||substr(dateFrom,4,2)) between DATE(:dateFrom) AND DATE(:dateTo) ORDER BY eventTime")
abstract suspend fun getSchedules(dateFrom: String, dateTo: String): List<DbSchedule>
@Query("SELECT statusId from DbSchedule WHERE careId = :careId")
abstract suspend fun getStatusId(careId: Int): Int
@Query("UPDATE DbSchedule SET scheduleStatusName = :scheduleStatusName WHERE scheduleId = :scheduleId")
abstract suspend fun updateReminder(scheduleId: Int, scheduleStatusName: String)
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertBreeds(list: List<DbBreeds>)
@Query("SELECT * FROM DbBreeds where speciesname = :speciesName ORDER BY breedname")
abstract suspend fun getBreeds(speciesName: String?): List<DbBreeds>?
@Query("SELECT speciesname FROM DbBreeds GROUP BY speciesname ORDER BY speciesname")
abstract fun getSpecies(): LiveData<List<String>>?
@Query("SELECT * FROM DbCareProviders WHERE category_name = :category and valid = 'Y'")
abstract suspend fun getProviders(category: String?): List<DbCareProviders>
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertProviders(list: List<DbCareProviders>)
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertNotifications(list: List<DBNotifications>)
@Query("SELECT * FROM DBNotifications order by receive_date desc")
abstract suspend fun getAllNotifications(): List<DBNotifications>
@Query("SELECT COUNT(*) from DBNotifications WHERE upper(message_status_name) = 'UNREAD'")
abstract suspend fun getCountUnreadNotifications(): Int
@Query("UPDATE DBNotifications SET message_status_name='OPEN_NOT_READ' where message_status_name = 'UNREAD'")
abstract suspend fun readNotifications()
@Query("UPDATE DBNotifications SET message_status_name='READ' WHERE notification_id=:id")
abstract suspend fun openNotification(id: Int)
@Query("UPDATE DBNotifications SET message_status_name='READ'")
abstract suspend fun openAllNotification()
@Query("UPDATE DBNotifications SET member_status_name='ACTIVE' WHERE notification_id=:id")
abstract suspend fun acceptFriendRequest(id: Int)
@Query("UPDATE DBNotifications SET member_status_name='INACTIVE' WHERE notification_id=:id")
abstract suspend fun ignoreFirenRequest(id: Int)
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertCareActivities(list: List<DBCareActivities>)
@Query("SELECT * FROM DBCareActivities")
abstract suspend fun getCareActivities(): List<DBCareActivities>
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract suspend fun insertUserAccounts(list: List<DbUserAccounts>)
/* @Update(entity = DBNotifications::class)
abstract fun ReadNotifications(notifications: List<DBNotifications> )*/
}
编辑:最后一个房间版本 2.3.0
// Room
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
// Room ktx
implementation 'androidx.room:room-ktx:2.3.0'
【问题讨论】:
-
我会尝试清除缓存并使缓存失效
-
我试过了,但没有帮助....
-
我看到您正在使用协程,但我没有在您的依赖项中明确看到它。如果您添加
implementation "androidx.room:room-coroutines:${versions.room}",它会起作用吗?在发表此评论时,最新版本是2.1.0-alpha04 -
找不到 androidx.room:room-ktx:2.1.0-alpha04。和 androidx.room:room-coroutines 的相同错误
标签: java android kotlin android-room android-livedata