loadRoomsMessages failed : Attempt to invoke virtual method 'java.lang.String org.matrix.androidsdk.MXDataHandler.getUserId()' on a null object reference
vorletzter opened this issue · 1 comments
Hi,
i am trying to wrap my head around the Usage of MXFileStore.
I am creating a new MXFile Store with
IMXStore store new MXFileStore(hsConfig, false, getApplicationContext());
and create (and open) the Session with
MXSession session = new MXSession.Builder(hsConfig, new MXDataHandler(store, credentials), getApplicationContext()).build(); session.getDataHandler().getStore().open();
(Btw. is there a reason why open() is never mentioned in the Readme? Took me quite some time looking through the VectorApp to find that missing piece :))
Afterwards i attach a MXStoreListener to the Store to proceed starting the EventStream, after onReady is called. This works fine, but only for the first launch.
After the second lunch the App crashes with:
/MXFileStore: loadRoomsMessages failed : Attempt to invoke virtual method 'java.lang.String org.matrix.androidsdk.MXDataHandler.getUserId()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.matrix.androidsdk.MXDataHandler.getUserId()' on a null object reference
at org.matrix.androidsdk.data.Room.(Room.java:157)
at org.matrix.androidsdk.data.store.MXFileStore.loadRoomMessages(MXFileStore.java:1253)
at org.matrix.androidsdk.data.store.MXFileStore.loadRoomsMessages(MXFileStore.java:1342)
at org.matrix.androidsdk.data.store.MXFileStore.access$100(MXFileStore.java:68)
at org.matrix.androidsdk.data.store.MXFileStore$1$1.run(MXFileStore.java:383)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
loadRoomsMessages fails
Fail to open the store in background
During the first launch of the App my Console gets flooded with warnings like:
E/RoomState: !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Null member '@>(removed)' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Null current user '@(removed)' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Looking at https://github.com/matrix-org/matrix-android-sdk/blob/497c7fa4a17df57dfe6e57e58b48dd174b395d01/matrix-sdk/src/main/java/org/matrix/androidsdk/data/RoomState.java#L513 i wonder, if LazyLoading might be the Issue here. Especially since "Null current user" is not supposed to happen - at least according to the Comment in that Function. :)
I have been looking at the riot-android Source, but i could not figure out why this seems to be a non-issue there. If this is not an issue with the SDK, i would appreciate a hint towards the correct usage of MXFileStore.
Maybe this is related to Bug #248 as well?
Okay.. i just noticed, that i have been looking at the "old"-Android Client.
If i attach the DataHandler to the Store as well (and not only the Store to the DataHandler), everything seems to work just fine
((MXFileStore) store).setDataHandler(dataHandler);