Android Question Help with runtime exception

rfresh

Well-Known Member
Licensed User
Longtime User
I'm seeing a runtime exception:
java.lang.RuntimeException: Object should first be initialized (Button).

...but as far as I can tell all my buttons are initialized. I must be over looking something.

Thanks for any help.

B4X:
#Region  Project Attributes 
    #ApplicationLabel: Minimums
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private ButtonMinuteAdd As Button
    Private ButtonSecondsAdd As Button
    Private LabelMinutes As Label
    Private LabelSeconds As Label
    Private ButtonMinuteMinus As Button
    Private ButtonSecondsMinus As Button
    Private LabelMinimums As Label
    Private pScreenHeight As Int
    Private pScreenWidth As Int
    Private minutes As Int
    Private seconds As Int

    Private LabelTitleMinutes As Label
    Private LabelTitleSeconds As Label
    Private ButtonStart As Button
    Private LabelCopyright As Label
    Private ButtonReset As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")

    minutes = 0
    seconds = 0
   
    pScreenHeight = GetDeviceLayoutValues.Height
    pScreenWidth = GetDeviceLayoutValues.Width
   
    ButtonMinuteAdd.Color = Colors.Cyan
    ButtonMinuteMinus.Color = Colors.Cyan
    ButtonMinuteAdd.TextColor = Colors.Black
    ButtonMinuteMinus.TextColor = Colors.Black
   
    ButtonSecondsAdd.Color = Colors.Cyan
    ButtonSecondsMinus.Color = Colors.Cyan
    ButtonSecondsAdd.TextColor = Colors.Black
    ButtonSecondsMinus.TextColor = Colors.Black

    ButtonStart.Color = Colors.Cyan
    ButtonStart.TextColor = Colors.Black
    ButtonReset.Color = Colors.Cyan
    ButtonReset.TextColor = Colors.Black
   
    LabelTitleMinutes.Color = Colors.Magenta
    LabelTitleSeconds.Color = Colors.Magenta
   
    LabelMinutes.Color = Colors.Cyan
    LabelMinutes.TextColor = Colors.Black
   
    LabelSeconds.Color = Colors.Cyan
    LabelSeconds.TextColor = Colors.Black

    LabelCopyright.Width = pScreenWidth * 0.92
   
    LabelMinimums.Color = Colors.Red
    LabelMinimums.Width = pScreenWidth * 0.92
    LabelMinimums.Height = pScreenHeight * 0.38
    LabelMinimums.Top = pScreenHeight * 0.56

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub ButtonMinuteAdd_Click
    minutes = minutes + 1
    LabelMinutes.Text = minutes
End Sub

Sub ButtonMinuteMinus_Click
    minutes = minutes - 1
    LabelMinutes.Text = minutes
End Sub

Sub ButtonSecondsAdd_Click
    seconds = seconds + 5
    LabelSeconds.Text = seconds
End Sub

Sub ButtonSecondsMinus_Click
    seconds = seconds - 5
    LabelSeconds.Text = seconds
End Sub

Sub ButtonStart_Click
   
End Sub

Sub ButtonReset_Click
   
End Sub


B4X:
Logger connected to:  LGE VS995
--------- beginning of system
--------- beginning of main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 67 (Main)
java.lang.RuntimeException: Object should first be initialized (Button).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.ViewWrapper.setColor(ViewWrapper.java:214)
    at b4a.minimums.main._activity_create(main.java:444)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
    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 b4a.minimums.main.afterFirstLayout(main.java:104)
    at b4a.minimums.main.access$000(main.java:17)
    at b4a.minimums.main$WaitForLayout.run(main.java:82)
    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:6710)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 67 (Main)
java.lang.RuntimeException: Object should first be initialized (Button).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.ViewWrapper.setColor(ViewWrapper.java:214)
    at b4a.minimums.main._activity_create(main.java:444)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
 

DonManfred

Expert
Licensed User
Longtime User
Upload a sample project which shows the issue. I guess one of the buttons is not part of the Layout!?
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Right...but see attachment...line 67 is a blank line...
 

Attachments

  • 2018-12-04_092115.png
    2018-12-04_092115.png
    7.4 KB · Views: 172
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Right...but see attachment...line 67 is a blank line...
Yes, but the closest line to that that references a button is ButtonReset, so I'd start there.

Also, clean your project (Tools -> Clean Project or 'Ctrl-P') and then run it again, hopefully the error line number will sync back up.
 
Upvote 0
Top