I picked up this code a while ago and now need to do something similar, i.e. sending an action to my service, but it doesn't work.
I'm getting the following error:
[DEBUG]
--------- beginning of main
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Scheduling at 1537165012798
Error occurred on line: 62 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference
at android.content.ComponentName.<init>(ComponentName.java:131)
at android.content.Intent.<init>(Intent.java:6347)
at anywheresoftware.b4a.keywords.Common.createPendingIntentForAlarmManager(Common.java:925)
at anywheresoftware.b4a.keywords.Common.StartServiceAt(Common.java:903)
at service.demo.main._schedule_service(main.java:474)
at service.demo.main._btnscheduleintent_click(main.java:434)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6877)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
[/DEBUG]
line 62 is the startserviceat line.
What is wrong please ?
B4X:
Sub schedule_service(secs As Int)
Dim i As Intent, x As Long
x = DateTime.Now + (secs * DateTime.TicksPerSecond)
Log("Scheduling at " & x)
i.Initialize("", "")
i.SetComponent(Application.PackageName & "/.testservice")
i.Action = "x" & secs
StartServiceAt(i,x,True)
End Sub
I'm getting the following error:
[DEBUG]
--------- beginning of main
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Scheduling at 1537165012798
Error occurred on line: 62 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Class.getName()' on a null object reference
at android.content.ComponentName.<init>(ComponentName.java:131)
at android.content.Intent.<init>(Intent.java:6347)
at anywheresoftware.b4a.keywords.Common.createPendingIntentForAlarmManager(Common.java:925)
at anywheresoftware.b4a.keywords.Common.StartServiceAt(Common.java:903)
at service.demo.main._schedule_service(main.java:474)
at service.demo.main._btnscheduleintent_click(main.java:434)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6877)
at android.widget.TextView.performClick(TextView.java:12651)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
[/DEBUG]
line 62 is the startserviceat line.
What is wrong please ?