【发布时间】:2018-11-01 17:15:46
【问题描述】:
我正在尝试在 Room 中插入 response.body(),这是 User,但我得到了
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 23714 (AsyncTask #2)
它显示在RecyclerView,但是当我尝试缓存它时,我的应用程序崩溃了。
这里是代码
private void refreshUser() {
executor.execute(new Runnable() {
@Override
public void run() {
try {
retrofit2.Response<User> response=webservice.getUser("1").execute();
User fromNetwork=response.body();
mUserDao.insertUser(fromNetwork);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
我正在关注this 我的应用指南。
这是DAO方法
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertUser(User user);
用户实体(响应正文)
@Entity(tableName = "user_table")
public class User {
@PrimaryKey
@NonNull
private String uid;
@NonNull
@ColumnInfo(name = "password")
private String password;
@SerializedName("first_name")
@ColumnInfo(name = "first_name")
private String firstName;
@SerializedName("last_name")
@ColumnInfo(name = "last_name")
private String lastName;
@ColumnInfo(name = "role")
private int role;
@ColumnInfo(name = "topic")
private String topic;
@ColumnInfo(name = "lab")
private String lab;
//constructor, setters and getters
}
还有视图模型
public class UserViewModel extends AndroidViewModel {
private AppRepository mRepository;
public UserViewModel(Application application) {
super(application);
mRepository=new AppRepository(application);
}
public LiveData<User> getUser(String username) {
return mRepository.getUser(username);
}
}
【问题讨论】:
-
能贴出道法、响应体和房间模型吗?
-
我编辑了我的问题@Ezzy
标签: android retrofit2 android-room segmentation-fault