I am wrapping a Lib which used a Service. It crashes when i try to connect in the Lib.
In the connect the lib starts the Service.
Inside the Service there is a Method which uses getBaseContext() but it crashes at this line in the Service:
The
seems to be from the Android Activity or so. don´t know exactly.
maybe android.content.ContextWrapper
The Source of the Service is attached.
Any hints how i can change the Service to get the right reference to the b4a Activity?
In the connect the lib starts the Service.
Inside the Service there is a Method which uses getBaseContext() but it crashes at this line in the Service:
B4X:
private void LoadPreferences(Boolean NotifyOfChanges) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
B4X:
getBaseContext()
maybe android.content.ContextWrapper
Logger verbunden mit: 9885e6514556383552
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
LogMessage: Starting Service
main_btnconnect_click (java line: 365)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at android.content.ComponentName.<init>(ComponentName.java:128)
at android.content.Intent.<init>(Intent.java:5359)
at com.ntrip.NTrip.doBindService(NTrip.java:276)
at com.ntrip.NTrip.Connect(NTrip.java:244)
at de.donmanfred.NTripwrapper.Connect(NTripwrapper.java:95)
at b4a.example.main._btnconnect_click(main.java:365)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6213)
at android.widget.TextView.performClick(TextView.java:11074)
at android.view.View$PerformClick.run(View.java:23645)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
LogMessage: Starting Service
main_btnconnect_click (java line: 365)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at android.content.ComponentName.<init>(ComponentName.java:128)
at android.content.Intent.<init>(Intent.java:5359)
at com.ntrip.NTrip.doBindService(NTrip.java:276)
at com.ntrip.NTrip.Connect(NTrip.java:244)
at de.donmanfred.NTripwrapper.Connect(NTripwrapper.java:95)
at b4a.example.main._btnconnect_click(main.java:365)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6213)
at android.widget.TextView.performClick(TextView.java:11074)
at android.view.View$PerformClick.run(View.java:23645)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
The Source of the Service is attached.
Any hints how i can change the Service to get the right reference to the b4a Activity?