Android Question ShortcutBadger

Declan

Well-Known Member
Licensed User
Longtime User
I have the following error when running:
B4X:
Sub setBadges
    badger1.SetBadge(imgNewMail, 8)
End Sub
The imgNewMail is created in the Visual Designer and is not initialized in code:
B4X:
Sub Globals
    Private dialog As B4XDialog
    Private xui As XUI
    Private ImageView1 As B4XView
    Public API_KEY As String
    Private imgNewMail As B4XView <---------------------
    Private badger1 As Badger
End Sub
My Error:
B4X:
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 19 (Badger)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at b4a.agritrax.badger._setbadge(badger.java:77)
    at b4a.agritrax.main._setbadges(main.java:540)
    at b4a.agritrax.main._activity_create(main.java:446)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.agritrax.main.afterFirstLayout(main.java:105)
    at b4a.agritrax.main.access$000(main.java:17)
    at b4a.agritrax.main$WaitForLayout.run(main.java:83)
    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:7225)
    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)
** Activity (main) Resume **
 

asales

Expert
Licensed User
Longtime User
Do you initialize the badger, before call setBadge?
B4X:
badger1.Initialize

badger1.SetBadge(label1, 10, xui.Color_RGB(100,100,100))
 
Upvote 0
Top