Fcm service is crashing when the application runs for the first time

when I running the application for the first time, I getting the error:
2018-12-02 19:34:46.705 31187-31187/com.repocyber.repoapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.repocyber.repoapp, PID: 31187
java.lang.RuntimeException: Unable to instantiate service com.backendless.push.BackendlessFCMService: java.lang.NullPointerException: Attempt to invoke interface method ‘int android.content.SharedPreferences.getInt(java.lang.String, int)’ on a null object reference
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3449)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method ‘int android.content.SharedPreferences.getInt(java.lang.String, int)’ on a null object reference
at com.backendless.AndroidBackendlessPrefs.getNotificationIdGeneratorInitValue(AndroidBackendlessPrefs.java:188)
at com.backendless.Backendless.getNotificationIdGeneratorInitValue(Backendless.java:303)
at com.backendless.push.BackendlessFCMService.(BackendlessFCMService.java:50)
at java.lang.Class.newInstance(Native Method)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3446)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

after running the second time, all seems to be working
I disable device register still getting the error.

I fixed it, but it strange
need to init Backendless before I register device

I mean first line in code, and not only if I choose to

You need to init Backendless before you use any of our APIs

1 Like