gpt4 book ai didi

java - RxJava插入并返回Id方法(房间)调试

转载 作者:行者123 更新时间:2023-12-02 03:05:14 39 4
gpt4 key购买 nike

我试图从 Activity 中将一行插入 SQLITE 数据库,然后返回要存储在 Activity 中的变量中的 rowId。请参阅下面我使用的方法和逻辑。

  private void insert() {

Log.d(TAG, "saveNote: called.");
try {
// String automaticThoughtString = automaticThoughtET.getText().toString().trim();
Note note = new Note(userId, therapistId, "Test", 0, "", "", postedWorkout);
noteDao.insert(note)
.map(new Function<Long, Integer>() {
@Override
public Integer apply(Long aLong) throws Exception {
long l = aLong;
return (int) l;
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SingleObserver<Integer>() {
@Override
public void onSubscribe(Disposable d) {

}

@Override
public void onSuccess(Integer integer) {

sqCbtId = integer;
}

@Override
public void onError(Throwable e) {

}
});
} catch (Exception e) {
e.printStackTrace();
}

android studio 中的调试显示:

  W/System.err: java.lang.NullPointerException: Attempt to  invoke interface method 'io.reactivex.Single  com.example.persistence.dao.NoteDao.insert(com.example.persistenc   e.entity.Note)' on a null object reference
W/System.err: at com.example.ui.activities.NoteActivity.insert(NoteActivity.java:1 42)
at com.example.ui.activities.NoteActivity.access$000(NoteActivity.java:43)
at com.example.ui.activities.NoteActivity$1.onClick(NoteActivity.java:129)
at android.view.View.performClick(View.java:6897)
at android.view.View$PerformClick.run(View.java:26104)
at android.os.Handler.handleCallback(Handler.java:789)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

最佳答案

您的 noteDao 为 null,您在使用它之前没有初始化它。

关于java - RxJava插入并返回Id方法(房间)调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57026076/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com