Room@Dao编译跳转报错解决-没有用到的Dao会这样
编译提示
> Task :user_lib:compileDebugJavaWithJavac
����: Current JDK version 1.8.0_221-b11 has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.
E:\AndroidProject\lqbsProjects\lqbs_android\user_lib\src\main\java\com\lqbs\gyso\data\database\LoginInfoDao.java:19: ����: The query returns some columns [id, uuid, ip, location, terminal_type, time] which are not used by com.lqbs.gyso.data.http.LoginInfo.
You can use @ColumnInfo annotation on the fields to specify the mapping.
You can annotate the method with @RewriteQueriesToDropUnusedColumns to direct Room to rewrite your query to avoid fetching unused columns. com.lqbs.gyso.data.http.LoginInfo has some fields [name, email, passWord, headUrl, token] which are not returned by the query.
If they are not supposed to be read from the result, you can mark them with @Ignore annotation.
You can suppress this warning by annotating the method with @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH). Columns returned by the query: id, uuid, ip, location, terminal_type, time, state. Fields in com.lqbs.gyso.data.http.LoginInfo: name, email, passWord, headUrl, state, token.
LiveData<List<LoginInfo>> getLoginInfoByUUID(String uuid);
原因
项目中没有使用这个Dao。
解决
按提示提示说有如下解决办法:
1 这是1.8.0_221-b11的bug,可以升级jdk到11
2 使用@ColumnInfo 指定使用的列属性
3 使用@RewriteQueriesToDropUnusedColumns
4 添加@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)到方法前
试过方法4 有效
@Dao
public interface LoginInfoDao {
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT * FROM login_info_tb WHERE uuid=:uuid")
LiveData<List<LoginInfo>> getLoginInfoByUUID(String uuid);
}