Android Question Device adminstrator error

Devv

Active Member
Licensed User
Longtime User
B4X:
If admin.Enabled = False Then admin.Enable
when i use this code

im getting the following error message when i run that code from a service


** Activity (main) Pause, UserClosed = false **
job done
Error occurred on line: 639 (Internet)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
at anywheresoftware.b4a.objects.AdminManager.Enable(AdminManager.java:33)
at Project.Gammaskype.internet._receiver_finished(internet.java:2329)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Any ideas ?
 

Widget

Well-Known Member
Licensed User
Longtime User
Just off the top of my head, how about
if admin.Enabled = false then admin.Enable = true
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
EDIT : the problem was that it wont work from a service when i launched it from an activity it worked
thanks mr widget
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
If you are using B4A v5.20 or later, take a look at section 3 "Starter Service" in the B4AUserGuide.PDF.

"Everything seems to work fine during development. However the app "strangely" crashes from time
to time on the end user device.
The reason for those crashes is that the OS can start the process from a different activity or service.
For example if you use StartServiceAt and the OS kills the process while it is in the background.
Now the SQL object and the other resources will not be initialized. "
Please see the manual for the solution. Hope this helps.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…