iOS Question attempt to insert nil object from objects[49]

jahswant

Well-Known Member
Licensed User
Longtime User
I have this error when trying to.
B4X:
Dim PIp As String = DefaultPayTerminalMAP.Get("printer_address")
                Dim Pport As Int  = DefaultPayTerminalMAP.Get("printer_port")
                PayTerminal.Initialize("PayTerminal")
                PayTerminal.Connect(PIp, Pport, 0)
                Wait For (PayTerminal) PayTerminal_Connected (Successful As Boolean)                    
                Log("PayTerminal.IsInitialized = " & PayTerminal.IsInitialized)
                Log("PayTerminal.Connected = " & PayTerminal.Connected)                    
                If Successful Then                        
                    Log("PayTerminal.IsInitialized = " & PayTerminal.IsInitialized)
                    Log("PayTerminal.Connected = " & PayTerminal.Connected)                        
                    TerminalRequestStatus = "CONNECTED"                    
                    Log("TerminalRequestStatus = " & TerminalRequestStatus)                    
                    Log("PayTerminal.InputStream, = " & PayTerminal.InputStream.IsInitialized)
                    Log("PayTerminal.OutputStream = " & PayTerminal.OutputStream.IsInitialized) 
'The code app crashes here.                   
                    PayTerminalStream.Initialize(PayTerminal.InputStream, PayTerminal.OutputStream, "PayTerminalStream")
                    PayTerminalStream.Write(SendStr.GetBytes("UTF-8"))        
'The code app crashes here.     
PayTerminalStream.Initialize(PayTerminal.InputStream, PayTerminal.OutputStream, "PayTerminalStream")

Every thing works perfect with b4j and b4a.

It show

B4X:
PayTerminal.IsInitialized = false
PayTerminal.Connected = false
Error occurred on line: 15 (B4XPages)
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[49]
Stack Trace: (
  CoreFoundation       __exceptionPreprocess + 242
  libobjc.A.dylib      objc_exception_throw + 62
  CoreFoundation       -[__NSPlaceholderArray initWithObjects:count:] + 482
  CoreFoundation       +[NSArray arrayWithObjects:count:] + 40
  CHICPOS              -[ResumableSub_dashboardpage_SendPayTerminalRequest resume::] + 1886
  CHICPOS              -[b4i_dashboardpage _sendpayterminalrequest::::] + 670
  CoreFoundation       __invoking___ + 140
  CoreFoundation       -[NSInvocation invoke] + 302
  CHICPOS              +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
  CHICPOS              -[B4IShell runMethod:] + 376
 CHICPOS              -[B4IShell raiseEventImpl:method:args::] + 1618
 CHICPOS              -[B4IShellBI raiseEvent:event:params:] + 1350
 CHICPOS              -[b4i_dashboardpage _processmixedpayments:] + 183
 CHICPOS              -[b4i_dashboardpage _btnsubmitcartpay_click:] + 2219
 CoreFoundation       __invoking___ + 140
 CoreFoundation       -[NSInvocation invoke] + 302
 CHICPOS              +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
 CHICPOS              -[B4IShell runMethod:] + 376
 CHICPOS              -[B4IShell raiseEventImpl:method:args::] + 1618
 CHICPOS              -[B4IShellBI raiseEvent:event:params:] + 1350
 CHICPOS              __33-[B4I raiseUIEvent:event:params:]_block_invoke + 48
 libdispatch.dylib    _dispatch_call_block_and_release + 12
 libdispatch.dylib    _dispatch_client_callout + 8
 libdispatch.dylib    _dispatch_main_queue_drain + 1421
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 31
 CoreFoundation       __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
 CoreFoundation       __CFRunLoopRun + 2515
 CoreFoundation       CFRunLoopRunSpecific + 550
 GraphicsServices     GSEventRunModal + 137
 UIKitCore            -[UIApplication _run] + 875
 UIKitCore            UIApplicationMain + 123
 CHICPOS              main + 96
 dyld                 start_sim + 10
 ???                  0x0 + 4496971056
)
 
Solution
Where do these values come from? The logs are not clear.

I guess that one of the strings or objects is Null. If you clean the project (Ctrl + P) before running it in debug mode and don't put breakpoints, it will probably crash as in release mode. This can help you find the problematic spot.

jahswant

Well-Known Member
Licensed User
Longtime User
this is the code I use.
B4X:
    If File.Exists(xui.DefaultFolder,"DefaultPayTerminal.MAP") = True Then
    Dim DefaultPayTerminalMAP As Map = B4XPages.MainPage.RetrieveEncryptedMap("DefaultPayTerminal.MAP")
    Log("DefaultPayTerminalMAP= " & DefaultPayTerminalMAP)

        Dim Printer_Type As String = DefaultPayTerminalMAP.Get("printer_type")
        Select Printer_Type
        Case "WIFI"
                Dim PIp As String = DefaultPayTerminalMAP.Get("printer_address")
                Dim Pport As Int  = DefaultPayTerminalMAP.Get("printer_port")
                PayTerminal.Initialize("PayTerminal")
                PayTerminal.Connect(PIp, Pport, 0)
                Wait For (PayTerminal) PayTerminal_Connected (Successful As Boolean)
                If Successful Then
                    Log("PayTerminal.IsInitialized = " & PayTerminal.IsInitialized)
                    Log("PayTerminal.Connected = " & PayTerminal.Connected)
                    Log("PayTerminal.Successful = " & Successful)
                    TerminalRequestStatus = "CONNECTED"
                    Log("TerminalRequestStatus = " & TerminalRequestStatus)
                    Log("PayTerminal.InputStream, = " & PayTerminal.InputStream.IsInitialized)
                    Log("PayTerminal.OutputStream = " & PayTerminal.OutputStream.IsInitialized)
                    PayTerminalStream.Initialize(PayTerminal.InputStream, PayTerminal.OutputStream, "PayTerminalStream")
                    PayTerminalStream.Write(SendStr.GetBytes("UTF-8"))
                Else If Not(Successful) Then
                    TerminalRequestStatus = "NOTCONNECTED"
                End If
            Case Else
            Toast.Show(Main.Loc.Localize("printingmodenotsupported"))
        End Select
    Else If File.Exists(xui.DefaultFolder,"DefaultPayTerminal.MAP") = False Then
        TerminalRequestStatus = "NOTCONNECTED"
        Toast.Show(Main.Loc.Localize("pleasesetdefaultprinter"))
    End If
It's always crashing in release mode. Works sometimes in debug but also perfect for B4A and B4j.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Where do these values come from? The logs are not clear.

I guess that one of the strings or objects is Null. If you clean the project (Ctrl + P) before running it in debug mode and don't put breakpoints, it will probably crash as in release mode. This can help you find the problematic spot.
 
Upvote 0
Solution

jahswant

Well-Known Member
Licensed User
Longtime User
I've been tring hard and today the error shifted to

B4X:
Error: <B4IExceptionWrapper: Error Domain=caught_exception Code=0 "*** -streamError only defined for abstract class.  Define -[B4IFastSocket streamError]!" UserInfo={NSLocalizedDescription=*** -streamError only defined for abstract class.  Define -[B4IFastSocket streamError]!}>


B4X:
Sub PayTerminalStream_Error
        Log("Error: " & LastException)
        Log("Terminated")
End Sub

I don't know if it's related but none of the values were null.
Where do these values come from?
The come from a saved map.
 
Upvote 0

Similar Threads

Top