Hello Experts - I worked hard to get the Widget show, however, I face a new challenge now. I'm duplicating the code I saw in an example and its not working when I try to create the widget manually. Any ideas? Below is the code.
Below is the error that I get when Adding the widget to the homescreen.
Not sure what is going on here. I removed and added the files. Also "cleaned" the project. But no go. Any help will be highly appreciated.
============================================================
See posts #3 and #9 for more details.
B4X:
#Region Module Attributes
#StartAtBoot: False
#End Region
'Service module
Sub Process_Globals
Dim rv As RemoteViews
Dim var11 As String
Dim var22 As String
Dim setpref As PreferenceManager
Dim wdSMS As PhoneSms
Dim imageFiles() As String
imageFiles = Array As String("send.png") 'file is added to the library and exists.
Dim currentImage As Int
End Sub
Sub Service_Create
'Set the widget to update every day
rv = ConfigureHomeWidget("WSMS", "rv", 60, "SafetyFirst SMS",True)
var11 = setpref.GetString("def1") '#
var22 = setpref.GetString("def3") 'msg
'LOG shows that the values are fetched
End Sub
Sub Service_Start (StartingIntent As Intent)
rv.HandleWidgetEvents(StartingIntent)
End Sub
Sub rv_RequestUpdate
SetTime
rv.UpdateWidget
End Sub
Sub rv_Disabled
StopService("")
End Sub
Sub Service_Destroy
End Sub
Sub SetTime
rv.SetText("Label1", "Send SMS [" & var22 & "] to " & var11)
End Sub
Sub imgB_Click
currentImage = (currentImage + 1) Mod imageFiles.Length
rv.SetImage("imgB", LoadBitmap(File.DirAssets, imageFiles(currentImage)))
rv.UpdateWidget
rv.SetText("Label1","SMS Sent")
Log("started")
wdSMS.Send2(var11,var22,True,True)
ToastMessageShow("Sent...",False)
End Sub
Below is the error that I get when Adding the widget to the homescreen.
B4X:
** Service (widgetservice) Create **
java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:95)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:83)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:77)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.createRemoteViews(RemoteViewsWrapper.java:58)
at com.shuvrobasu.IReachedSafelyApp.widgetservice._service_create(widgetservice.java:162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.shuvrobasu.IReachedSafelyApp.widgetservice.onCreate(widgetservice.java:46)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchFieldException: widgetservice_imgb
at java.lang.ClassCache.findFieldByName(ClassCache.java:446)
at java.lang.Class.getField(Class.java:864)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:93)
... 20 more
java.lang.RuntimeException: Unable to create service com.shuvrobasu.IReachedSafelyApp.widgetservice: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1955)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.shuvrobasu.IReachedSafelyApp.widgetservice.onCreate(widgetservice.java:46)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
... 10 more
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:95)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:83)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:77)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.createRemoteViews(RemoteViewsWrapper.java:58)
at com.shuvrobasu.IReachedSafelyApp.widgetservice._service_create(widgetservice.java:162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
... 13 more
Caused by: java.lang.NoSuchFieldException: widgetservice_imgb
at java.lang.ClassCache.findFieldByName(ClassCache.java:446)
at java.lang.Class.getField(Class.java:864)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:93)
... 20 more
** Service (widgetservice) Create **
java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:95)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:83)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:77)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.createRemoteViews(RemoteViewsWrapper.java:58)
at com.shuvrobasu.IReachedSafelyApp.widgetservice._service_create(widgetservice.java:162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.shuvrobasu.IReachedSafelyApp.widgetservice.onCreate(widgetservice.java:46)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchFieldException: widgetservice_imgb
at java.lang.ClassCache.findFieldByName(ClassCache.java:446)
at java.lang.Class.getField(Class.java:864)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:93)
... 20 more
java.lang.RuntimeException: Unable to create service com.shuvrobasu.IReachedSafelyApp.widgetservice: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1955)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.shuvrobasu.IReachedSafelyApp.widgetservice.onCreate(widgetservice.java:46)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1945)
... 10 more
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: widgetservice_imgb
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:95)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:83)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.loadLayoutHelper(RemoteViewsWrapper.java:77)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.createRemoteViews(RemoteViewsWrapper.java:58)
at com.shuvrobasu.IReachedSafelyApp.widgetservice._service_create(widgetservice.java:162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
... 13 more
Caused by: java.lang.NoSuchFieldException: widgetservice_imgb
at java.lang.ClassCache.findFieldByName(ClassCache.java:446)
at java.lang.Class.getField(Class.java:864)
at anywheresoftware.b4a.objects.RemoteViewsWrapper.getIdForView(RemoteViewsWrapper.java:93)
... 20 more
Not sure what is going on here. I removed and added the files. Also "cleaned" the project. But no go. Any help will be highly appreciated.
============================================================
See posts #3 and #9 for more details.
Last edited: