B4J Question [SOLVED] Maddening list bug

JackKirk

Well-Known Member
Licensed User
Longtime User
I've tried everything I can think of to fix this - last resort: post a question...

Here is the code:
B4X:
Log(xxxx.Size)
Log(xxxx.IsInitialized)
        'For each ticket web request file...
        For wrk_ptr = 0 To xxxx.Size - 1                        '<<<<< this is line 631
wrk_ptr is an Int

Here is the log:
Waiting for debugger to connect...
Program started.
0
true
Error occurred on line: 631 (Main)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:134)
at b4j.example.main$ResumableSub_Event_obj_check_web_backlog_timer_Tick.resume(main.java:2217)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:153)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:102)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1103)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
I have tried everything including cleaning the project, shutting down the PC etc but still it persists.

I know I'm doing something stupid but what...
 
Solution
I found it!!!

The code that was producing the error was a modification of code I have had running for 3 years.

So I went back to the archived earlier copy and went slowly thru the modifications I had made.

In the subroutine that was bombing I had made a change that potentially resulted in another totally unrelated list being referenced before it was initialized.

For some totally bizarre reason, this was causing the reference to the other list (that was initialized) to bomb - before the bad reference was even executed.

So moral is: if you get a list bombing on you as "uninitialised" and you can't work out why - check all other lists in the same routine.

I'm guessing this may apply to maps also?

Does this qualify as a bug? - see...

DonManfred

Expert
Licensed User
Longtime User
Log(xxxx.IsInitialized)
If this logs false then your list is not initialized.
Trying to access the size after this check on a not initialied list gives the error.

B4X:
Log(xxxx.IsInitialized)
if xxx.Isinitialied then
  'For each ticket web request file...
  For wrk_ptr = 0 To xxxx.Size - 1 
  next
end if
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
test:
Have you checked the variable name?

B4X:
    Dim MyList As List
    MyList.Initialize

    Log("---For Not Data---")
    
    Log(MyList.IsInitialized)
    Log(MyList.Size)
    
    For i = 0 To MyList.Size -1
        Log(MyList.Get(i))
    Next
    
'    For Each i As Int In MyList
'        Log(i)
'    Next
    
    Log("---For with Data---")
    
    MyList = Array (100, 200, 300, 400, 500)
    
    Log(MyList.IsInitialized)
    Log(MyList.Size)
    
    For i = 0 To MyList.Size -1
        Log(MyList.Get(i))
    Next
    
'    For Each i As Int In MyList
'        Log(i)
'    Next

1632125790285.png
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Does this only happen under debug? Is it OK when in release mode. There was a debug bug at one time that looked like this.
agraham - it does it in release mode too!

B4X:
B4X:
if xxxx.Isinitialied and xxxx.Size > 0 then
  for next loop here....
end if
DonManfred - if I change the code to:
B4X:
Log(xxxx.Size)
Log(xxxx.IsInitialized)
        If xxxx.Size > 0 Then                '<<<<<< fails on this statement (632)
        'For each ticket web request file...
        For wrk_ptr = 0 To xxxx.Size - 1

Waiting for debugger to connect...
Program started.
0
true
Error occurred on line: 632 (Main)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:134)
at b4j.example.main$ResumableSub_Event_obj_check_web_backlog_timer_Tick.resume(main.java:2237)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:153)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:102)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1103)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Again. Upload a small project showing the issue.

Probably the error is happening on another line of what you posted.

I´m not further interested to help with this less info, no example showing the problem. Good luck.

b4j.example.main$ResumableSub_Event_obj_check_web_backlog_timer_Tick.resume(main.java:2237)
what is java line 2237. Post the relevant lines.
 
Last edited:
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Again. Upload a small project showing the issue.
I tried to do this but of course, it worked.
b4j.example.main$ResumableSub_Event_obj_check_web_backlog_timer_Tick.resume(main.java:2237)
what is java line 2237. Post the relevant lines.
The code is in a timer tick event (Event_obj_check_web_backlog_timer_Tick) that has some resumable components.

It is a major bit of code.
I´m not further interested to help with this less info, no example showing the problem. Good luck.
I'm as frustrated as you are, believe me, what I am really struggling with is that the immediately preceding log statements indicate all should be OK.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
It just keeps on getting weirder, I tried this:
B4X:
Log(xxxx.Size)
Log(xxxx.IsInitialized)
        Private garbage As Int
        garbage = xxxx.Size
        'For each ticket web request file...
        For wrk_ptr = 0 To garbage - 1          '<<<< this is line 634 it is failing on
Log is:
Waiting for debugger to connect...
Program started.
0
true
Error occurred on line: 634 (Main)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:134)
at b4j.example.main$ResumableSub_Event_obj_check_web_backlog_timer_Tick.resume(main.java:2224)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:153)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:102)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1103)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
There is something wrong there. The error line 634 quoted does not reference a List. Check the declared type of work_ptr.
Yes, here is a bit more detail:
B4X:
Log(xxxx.Size)
Log(xxxx.IsInitialized)
        Private garbage As Int
Log("ababab")
        garbage = xxxx.Size
Log("cdcdcd")
Log(GetType(wrk_ptr))
Log(GetType(wrk_ticket_web_request_file))
Log(GetType(xxxx))
        'For each ticket web request file...
        For wrk_ptr = 0 To garbage - 1          '<<<<<<bombing on line 639
Log("efefef")
            wrk_ticket_web_request_file = xxxx.Get(wrk_ptr)
Log is:
Waiting for debugger to connect...
Program started.
0
true
ababab
cdcdcd
java.lang.Integer
java.lang.String
java.util.ArrayList
Error occurred on line: 639
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:134)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:21)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:153)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:102)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1103)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
and for good measure here is a screenshot:
bomb.png
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
At the risk of going down a rabbit hole post the main.java file in the project Objects/src/.... folder tree
The project is part of a ticketing system which I don't want broadcast - I note you don't answer questions by PM but I will try my luck and send it to you that way...
 
Upvote 0
Top