每次我尝试获取记录时都会得到null异常,但是我能够正确插入记录。请帮助我,我真的很震惊
用于从会议室数据库中获取记录的代码段
>>> p = Point(1,2,3)
>>> asdict(p)
{'x': 1, 'y': 2, 'z': 3}
>>> astuple(p)
(1, 2, 3)
// DAO
@Override
public LoginSessionEntity getLoginSessionRecord(final String sessionId) {
final LoginSessionEntity[] status = new LoginSessionEntity[1];
executor.execute(new Runnable() {
@Override
public void run() {
status[0] = iglDAO.getLoginSessionRecord(sessionId);
}
});
return status[0];
}
实体
@Transaction
@Query("SELECT * FROM login_session where sessionId =:sessionid")
LoginSessionEntity getLoginSessionRecord(String sessionid );
例外
@Entity(tableName = AppConstants.TableNames.TABLE_LOGIN_SESSION)
public class LoginSessionEntity {
@PrimaryKey
@NonNull
@SerializedName("SessionId")
@Expose
private Integer sessionId;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_FIRST_USER_REG_NO)
@SerializedName("RegistrationNo")
@Expose
private String registrationNoOne;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_SECOND_USER_REG_NO)
private String registrationNoTwo;
@SerializedName("Name")
@Expose
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_FIRST_USER_NAME)
private String nameOne;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_SECOND_USER_NAME)
private String nametwo;
@SerializedName("Rank")
@Expose
private String rank;
@SerializedName("URL")
@Expose
private String uRL;
@SerializedName("LoginTime")
@Expose
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_FIRST_LOGIN_TIME)
private String loginTimeOne;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_SECOND_LOGIN_TIME)
private String loginTimeTwo;
@SerializedName("UserTypeId")
@Expose
private int userTypeId;
@SerializedName("BaseURL")
@Expose
private String baseURL;
@SerializedName("UnitCode")
@Expose
private String unitCode;
private String imei;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_FIRST_LOGIN_STATUS)
private boolean loginStatusOne;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_SECOND_LOGIN_STATUS)
private boolean loginStatusTwo;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_FIRST_LOGOUT_TIME)
private String logoutTimeOne;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_SECOND_LOGOUT_TIME)
private String logoutTimeTwo;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_FIRST_LOGIN_TYPE_ID)
private int loginTypeIdOne;
@ColumnInfo(name = AppConstants.ColumnNames.COLUMN_SECOND_LOGIN_TYPE_ID)
private int loginTypeIdTwo;
private int routeId;
private String sourceId;
@Ignore
private String message;
答案 0 :(得分:0)
在已实现的getLoginSessionRecord(final String sessionId)
方法中,该方法在当前线程上返回创建的数组。执行程序在单独的线程中运行内联可运行程序,因此在返回后设置值。相反,您可以允许主线程查询并直接使用接口方法。在会议室数据库生成器上调用allowMainThreadQueries()
,但这可能会减慢UI线程的速度。另一种解决方案是将LiveData用于异步到达数据库。查阅room accessing data文档以了解更多信息。