Android Question Prefs App change: java.lang.RuntimeException: Unable to create service xxx.starter:

SlashIT

Member
Licensed User
Longtime User
Hi everyone, I ran into a very strange problem: in a b4a app (default, at the moment it is not possible to switch to b4xpage) I implemented the use of push messages (FirebaseMessaging). The whole project works correctly (including push) but now I am implementing the option to open the app preferences so that the user can change the consent option to receive push notifications. Whether the preferences are opened from the App (intent) or with the app in the background, when I change the preferences the app crashes and generates this error:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
java.lang.RuntimeException: Unable to create service b4a.example.starter: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[])' on a null object reference
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4925)
    at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2407)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loopOnce(Looper.java:232)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8592)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[])' on a null object reference
    at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:164)
    at anywheresoftware.b4a.shell.Shell.start(Shell.java:102)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:105)
    at b4a.example.starter.onCreate(starter.java:34)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4912)
    ... 9 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[])' on a null object reference
    at anywheresoftware.b4a.shell.ShellConnector.sendControlMessage(ShellConnector.java:61)
    at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:124)
    ... 13 more

I attach a minimal project that worked the first time but now it crashes like in the main project.
I am trying it on pixel8a (Android 14)
B4A v.13.00(64bit)
Java jdk-19.0.2
Android-33
android:minSdkVersion="26" android:targetSdkVersion="33"
Anyone have any idea how to fix this?
 

Attachments

  • testPrefsB4A.zip
    2.8 KB · Views: 23

SlashIT

Member
Licensed User
Longtime User
Looks like you are testing it in debug mode. Test it in release mode instead.
tried in release mode and actually I have a more detailed debug: when the system app options are opened and I return to the app the starter service is recreated, and restarts a series of procedures that cause the app to conflict, causing the crash. Is it normal that when I return the starter service is recreated or is there a way to keep it active?
I tried both with
B4X:
Sub Service_Start (StartingIntent As Intent)
    Log("service start")
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
and with
B4X:
Sub Service_Start (StartingIntent As Intent)
    Log("service start")
    'Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
in Starter Service_TaskRemoved, Application_Error and Service_Destroy are not activated.
 
Upvote 0

SlashIT

Member
Licensed User
Longtime User
None of them will be raised when the process is killed by the OS.
ok, but is it normal for the starter to be recreated? What I can't figure out is whether:
1) Android bug
2) b4a bug
3) I don't know
Now I have disabled the option but if the user changes the preferences while the app is running, it crashes...
As soon as I can I will recreate these conditions with kotlin so maybe I can give you some debugging information based on your answer to my 3 questions.
 
Upvote 0
Top