iOS Question [Solved] Error: object cannot be nil

StxTeam

Member
Licensed User
Hi everibody,
i receive this error

B4X:
Error occurred on line: 209 (IISApiCall)
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       _CFArgv + 0
  CoreFoundation       <redacted> + 1212
  SmartDragonAPP       -[B4IMap debug::] + 1040
  SmartDragonAPP       -[B4IShell getDebuggerVariable:] + 620
  SmartDragonAPP       -[B4IShell handleIncomingData:inputStream:] + 124
  SmartDragonAPP       -[B4IShellConnector readControlData:] + 160
  SmartDragonAPP       -[B4IShellConnector connect] + 2040
  SmartDragonAPP       -[B4IShellConnector run] + 40
 Foundation           <redacted> + 984
 libsystem_pthread.dylib             0x00000001844302c0 <redacted> + 128
 libsystem_pthread.dylib             0x0000000184430220 _pthread_start + 44
 libsystem_pthread.dylib             0x0000000184433cdc thread_start + 4
)
SignalHandler 6

B4X:
'########## function active when the http result as a success ##########
Sub JobDone (jobName As HttpJob)  

    'Dim tm As Cls_ToastMessage

    If jobName.Success = True Then
      
        Errore = 0
        GetData(jobName.GetString)
        If Errore  = 1 Then
            RetryExecuteQuery(jobName)
        End If
    Else
        'tm.Initialize("Job fail" & jobName.JobName,False)
        Log("ISS JOB Error: " & jobName.ErrorMessage)
'        ToastMessageShow("Error: " & job.ErrorMessage, True)
        Errore = 1
        RetryExecuteQuery(jobName)
    End If
  
    CallSub2(SourceTarget, "IISApiCall_Exec",jobName.JobName)
  
    jobName.Release
  
    IIS_Busy = False
End Sub

this is the part with error, when i try to read map

B4X:
'########## It excract 1 file Map with the data section of the json ##########
Sub GetData (Result As String)
  
    Dim Tm As Cls_ToastMessage
    Dim Json As JSONParser
    Dim Map1 As Map
    Try
        Log("WebApi_RxData: = " & Result)
        Json.Initialize(Result)
        Map1 = Json.NextObject
        Data = Map1.Get("Data")
        If Map1.ContainsKey("Version") Then
            GLB.Vers_SD_Code = Map1.Get("Version")
        End If
        Dim MapError As Map = Map1.Get("NotTrappedError")
    Catch
        Data.Initialize
        'set receive data error to decode
        Tm.Initialize(GLB.GetTranslation(TRANS.TXT_ERROR_WEBAPI_DECODE_ERROR,"WebAPI encode error"),False)
        Errore = 2
        IIS_Busy = False
    End Try
End Sub

when i try to decode e Json into a map from a WebServer, i'm using B4i v. 5.51, iHttpUtils2 v. 2.81 and hosted builder.

I looked for this: https://www.b4x.com/android/forum/t...not-be-nil-key-hc_username.59091/#post-372283 but i this it's not my case.

I've try to checkout my last released vers. from Git and it also doesn't work anymore (developed with B4i V. 5.0).

Can someone explain me what i'm doing wrong..?

Thanks
 
Last edited:

StxTeam

Member
Licensed User
I made some test, i tried to downgrade to B4I v 5.00 with iHttpUtils2 v. 2.62 and also iHttp v 1.01 and it works.

But i need function "jobName.Response.GetHeaders" so i update to iHttpUtils2 v. 2.81.

So i don't solve it......
 
Upvote 0

StxTeam

Member
Licensed User
B4X:
Application_Start
Class (b4i_cls_sql_gest) instance released.
Class (b4i_cls_sql_gest) instance released.
Class (b4i_cls_sql_gest) instance released.
Class (b4i_iosfunction) instance released.
{"IsAdmin":0,"IsLogged":0,"CallerType":1,"Culture":"en-GB","Version":"1.7.2"}
Application_Active
WebApi_RxData: = {"Data":{"Translations":{"TXT_spinning_mydashboard_new_dashboard_title":"Press to create a new dashboard","TXT_machine_data_idle_spindle_percentage":"%loss of idle spindles","RAYL_NormalBreakages_B":"Ongoing br B","RAYL_NormalBreakages_A":"Ongoing br A","ERR_CUSTOM":"Warning: {0}","TXT_Monitor_Widget_021_Descr":"Department breakages during the current shift","TXT_configuration_machines_models_edit_title":"Press to edit this Machine Model settings","ERR_SIGNALR_SIGNALR_TYPE_NULL":"You must provide the SignalR type","TXT_machine_previous_range_title":"Show the previous period","RAYL_ArticleCode":"Article Code","TXT_manage_license_infinity_license":"Never expires","ERR_FIELD_ONLY_POSITIVE":"This field must have a positive number","JA_TXT_jobs_not_scheduled":"Not scheduled","RAYL_TemplateNotDeleted":"template not deleted Kindly try again...","ITBOX3_ERR_get_shifts":"Shifts getting error: {0}","JA_TXT_glb_db_maintenance_plan":"Maintenance plan","TXT_select_the_color":"Select the color","ERR_LOADING_FACTORIES":"Error reading factories list","ERR_FIELD_ACCEPT_ONLY_ALPHANUMERIC_CHARACTERS":"This field only accepts  alphanumeric characters (A-Z and 0-9)","ERR_CALENDAR_STANDARD_SCHEDULE_NOT_ERASEABLE_GENERIC_REASON":"This schedule cannot be deleted","TXT_delete_standardschedule_confirmation_message":"Confirm schedule deletion?","TXT_user_profile_alarms_treeview_text":"Alarms manager","TXT_select_all":"Select all","ERR_DEPARTMENT_NOT_CHOSEN":"You must select at least one department","TXT_user_profile_name_field_title":"Your name","TXT_spinning_planning_delete_gantt_task_button_confirm_text":"This gantt task will be deleted.\u003cbr/\u003e\u003cbr/\u003eDo you confirm?","TXT_color_fieldset_legend_edit":"Edit color","TXT_UM_NE_DESCR":"Hank/Pound","ERR_PERFORMING_OPERATION":"Error performing operation","TXT_filedialog_drag_message":"Drop files here","TXT_color_fieldset_legend_view":"View color","ITBOX3_starting_program":"Starting IntellicomTBox3 program...","TXT_spinning_dept_statistics_avg_delivery_speed":"Avg delivery speed","TXT_stop_chart_no_operator":"No Operator","RAYL_GRAIN_YD":"gr/yd","TXT_first_access_customer_code_already_registered":"Customer code already registered","TXT_configuration_manage_departments_description_title":"Department description","ITBOX3_getting_current_lot":"Getting current lot.","TXT_tri_phase_current_L1L2_A":"Tri-Phase Current L1L2 (A)","TXT_tri_phase_current_L2L3_A":"Tri-Phase Current L2L3 (A)","TXT_UM_DEN":"den","TXT_UM_TPC":"TPC","TXT_UM_TPF":"TPF","TXT_UM_TPI":"TPI","TXT_UM_TPM":"TPM","TXT_UM_TPY":"TPY","TXT_log4net_started":"--- Started Logging System  ---","TXT_machine_data_idle_br":"Idle br","TXT_tri_phase_current_L3L1_A":"Tri-Phase Current L3L1 (A)","RAYL_NameforSaveasTemplate":"Enter the name for Save as Template","TXT_operator_delete_title_in_list":"Delete Operator","TXT_article_updated_successfully":"The article has been correctly updated","TXT_machine_data_no_machine_shift":"No machine shift","TXT_spinning_mydashboard_clone_dashboard_modal_title":"Clone Dashboard","TXT_color_delete_confirmation_message":"Confirm this color deletion?","TXT_spinning_dept_statistics_ukg_details_title":"Energy consumption","TXT_configuration_db_maintenance_plan_button_enable_success":"Task successfully enabled.","TXT_configuration_manage_machines_initialize_machine_ok_message":"TBOX `{0}` initialized correctly. Returned message: {1}","datetimepicker_selectDecade":"Select Decade","TXT_configuration_database_info_header_servicepack":"Service Pack:","TXT_pov_operators_avg_lot_changes_column_name":"Avg batch change time","TXT_Operation_OK_title":"Operation completed successfully","TXT_configuration_manage_monitor_manage_dashboard_save_no_widget":"You must provide at least a widget for the dashboard before save","TXT_spinning_planning_gantt_details_stopReason_label":"Change reason","TXT_spinning_dept_statistics":"Dept Statistics","TXT_menu_modules_spinning_lot_workplan":"Batch WorkPlan","TXT_configuration_ (message truncated)...
{"IsAdmin":0,"IsLogged":0,"CallerType":1,"Culture":"en-GB","Version":"1.7.2"}
Class (b4i_httpjob) instance released.
WebApi_RxData: = {"Data":{"License":{"Lists":[{"PKProject":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicProject":"SD","DescriptionProject":"LICENSE_project_smartdragon_description","PKCustomer":"2266b61c-3075-424e-b922-c1d747b161d8","Code":"LP","BusinessName":"Testing for develop (LP Code)","PKFactory":"61a84bcf-5e6c-475f-9413-cd3dba35ed32","MnemonicFactory":"FN","DescriptionFactory":" Factory for develop testing","IsPremium":true,"ExpireDateISO8601":"2019-12-01T00:00:00","SubLevels":[{"Enabled":true,"ExpireDateISO8601":"2019-12-01T00:00:00","SubLevels":[{"Enabled":true,"ExpireDateISO8601":"2019-12-01T00:00:00","SubLevels":[],"PK_Level":"2252e3f3-66c6-4dff-b940-1b03722981e8","FK_Project":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicLevel":"SPNPL","Description":"Planning","FK_Level":"ed66d163-e455-481d-83ab-6eb4a8f57a37","Core":false,"Global":false,"Defaults":[],"Levels":[],"Level_FK_Level":null,"Project":null}],"PK_Level":"ed66d163-e455-481d-83ab-6eb4a8f57a37","FK_Project":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicLevel":"SPN","Description":"Spinning","FK_Level":null,"Core":false,"Global":false,"Defaults":[],"Levels":[],"Level_FK_Level":null,"Project":null}]},{"PKProject":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicProject":"SD","DescriptionProject":"LICENSE_project_smartdragon_description","PKCustomer":"2266b61c-3075-424e-b922-c1d747b161d8","Code":"LP","BusinessName":"Testing for develop (LP Code)","PKFactory":null,"MnemonicFactory":null,"DescriptionFactory":null,"IsPremium":false,"ExpireDateISO8601":null,"SubLevels":[{"Enabled":true,"ExpireDateISO8601":null,"SubLevels":[],"PK_Level":"da0d90a6-e08d-44cc-9032-0439ec27e92c","FK_Project":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicLevel":"CoreC","Description":"System configuration","FK_Level":null,"Core":true,"Global":true,"Defaults":[],"Levels":[],"Level_FK_Level":null,"Project":null},{"Enabled":true,"ExpireDateISO8601":null,"SubLevels":[],"PK_Level":"b3388c12-ac4a-448b-8d7f-3ef80e92fd4f","FK_Project":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicLevel":"CoreU","Description":"User Administration","FK_Level":null,"Core":true,"Global":true,"Defaults":[],"Levels":[],"Level_FK_Level":null,"Project":null}]},{"PKProject":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicProject":"SD","DescriptionProject":"LICENSE_project_smartdragon_description","PKCustomer":"2266b61c-3075-424e-b922-c1d747b161d8","Code":"LP","BusinessName":"Testing for develop (LP Code)","PKFactory":"2ce6f5d4-767a-47c8-8e52-f2a63b7d34af","MnemonicFactory":"TT","DescriptionFactory":"Test","IsPremium":false,"ExpireDateISO8601":null,"SubLevels":[{"Enabled":true,"ExpireDateISO8601":null,"SubLevels":[{"Enabled":false,"ExpireDateISO8601":null,"SubLevels":[],"PK_Level":"2252e3f3-66c6-4dff-b940-1b03722981e8","FK_Project":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicLevel":"SPNPL","Description":"Planning","FK_Level":"ed66d163-e455-481d-83ab-6eb4a8f57a37","Core":false,"Global":false,"Defaults":[],"Levels":[],"Level_FK_Level":null,"Project":null}],"PK_Level":"ed66d163-e455-481d-83ab-6eb4a8f57a37","FK_Project":"972db937-be1f-477c-8636-ceaf657536c7","MnemonicLevel":"SPN","Description":"Spinning","FK_Level":null,"Core":false,"Global":false,"Defaults":[],"Levels":[],"Level_FK_Level":null,"Project":null}]}]},"Modules":[{"PK_Module":"ff092130-6b29-4e33-8bdf-1ac5191b735d","MnemonicModule":"CoreC","Name":"TXT_module_configuration","Description":"TXT_module_configuration_short_description","Order":2,"Global":true,"NeededArea":false,"HP":"MODULE_CONFIGURATION_HP","CoreMnemonicAuth":null,"GLB_Alarms":[],"GLB_Cal_RotationShifts":[],"GLB_Cal_ShiftTypes":[],"GLB_Dash_Dashboards":[],"GLB_Dash_WidgetsCategories":[],"GLB_DepartmentsTypes":[],"GLB_MachinesGroups":[],"GLB_MachinesModels":[],"GLB_MachinesTypes":[],"GLB_ModulesSubLevels":[],"GLB_RAYL_Categories":[],"GLB_Rpt_Categories":[],"GLB_StopReasons":[],"GLB_Usr_Auths":[],"GLB_Usr_AuthGuids":[],"GLB_Usr_AuthTypes":[]},{"PK_Module":"20caaae0-7b36-4037-adb0-f749ee5ad317", (message truncated)...
31
Error occurred on line: 38 (Cls_Prerequisites)
*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: MaxInputValue)
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       _CFArgv + 0
  CoreFoundation       <redacted> + 940
  SmartDragonAPP       -[B4IJSONGenerator convertMapToJO:] + 780
  SmartDragonAPP       -[B4IJSONGenerator convertListToJO:] + 468
  SmartDragonAPP       -[B4IJSONGenerator toString:] + 176
  SmartDragonAPP       -[b4i_cls_prerequisites _initialize:::] + 1876
  SmartDragonAPP       -[b4i_glb _issloadprerequisites:] + 600
  SmartDragonAPP       -[b4i_main _iisapicall_exec:] + 2500
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 292
 SmartDragonAPP       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 SmartDragonAPP       -[B4IShell runMethod:] + 448
 SmartDragonAPP       -[B4IShell raiseEventImpl:method:args::] + 2172
 SmartDragonAPP       -[B4IShellBI raiseEvent:event:params:] + 1580
 SmartDragonAPP       -[B4ICommon CallSub4::::] + 344
 SmartDragonAPP       -[B4ICommon CallSub2::::] + 360
 SmartDragonAPP       -[b4i_iisapicall _jobdone::] + 1848
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 292
 SmartDragonAPP       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 SmartDragonAPP       -[B4IShell runMethod:] + 448
 SmartDragonAPP       -[B4IShell raiseEventImpl:method:args::] + 2172
 SmartDragonAPP       -[B4IShellBI raiseEvent:event:params:] + 1580
 SmartDragonAPP       -[B4ICommon CallSub4::::] + 344
 SmartDragonAPP       -[B4ICommon CallSub2::::] + 360
 SmartDragonAPP       -[b4i_httpjob _complete::] + 888
 SmartDragonAPP       -[b4i_httputils2service _completejob::::] + 1288
 SmartDragonAPP       -[b4i_httputils2service _hc_responsesuccess::] + 636
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 292
 SmartDragonAPP       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 SmartDragonAPP       -[B4IShell runMethod:] + 448
 SmartDragonAPP       -[B4IShell raiseEventImpl:method:args::] + 2172
 SmartDragonAPP       -[B4IShellBI raiseEvent:event:params:] + 1580
 SmartDragonAPP       __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 268
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 92
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1068
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1924
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 104
 UIKitCore            UIApplicationMain + 212
 SmartDragonAPP       main + 124
 libdyld.dylib        <redacted> + 4
)
 
Upvote 0

StxTeam

Member
Licensed User
Sorry my mistake, in the first post i used a program test. I attach this test, so you'll can test it.
You must only insert the right URL to our Server, i send it by private conversation.
 

Attachments

  • Test_b4i.zip
    99.8 KB · Views: 250
Upvote 0

StxTeam

Member
Licensed User
Sorry

the error appens in row "Log(a.ToString)"

the full error in test program is:
B4X:
Error occurred on line: 156 (IISApiCall)
*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: Data)
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       _CFArgv + 0
  CoreFoundation       <redacted> + 940
  SmartDragonAPP       -[B4IJSONGenerator convertMapToJO:] + 780
  SmartDragonAPP       -[B4IJSONGenerator toString:] + 152
  SmartDragonAPP       -[b4i_iisapicall _getdata::] + 1856
  SmartDragonAPP       -[b4i_iisapicall _jobdone::] + 784
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
 SmartDragonAPP       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 SmartDragonAPP       -[B4IShell runMethod:] + 448
 SmartDragonAPP       -[B4IShell raiseEventImpl:method:args::] + 2172
 SmartDragonAPP       -[B4IShellBI raiseEvent:event:params:] + 1580
 SmartDragonAPP       -[B4ICommon CallSub4::::] + 344
 SmartDragonAPP       -[B4ICommon CallSub2::::] + 360
 SmartDragonAPP       -[b4i_httpjob _complete::] + 888
 SmartDragonAPP       -[b4i_httputils2service _completejob::::] + 1288
 SmartDragonAPP       -[b4i_httputils2service _hc_responsesuccess::] + 636
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 292
 SmartDragonAPP       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 SmartDragonAPP       -[B4IShell runMethod:] + 448
 SmartDragonAPP       -[B4IShell raiseEventImpl:method:args::] + 2172
 SmartDragonAPP       -[B4IShellBI raiseEvent:event:params:] + 1580
 SmartDragonAPP       __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 268
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 92
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1068
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1924
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 104
 UIKitCore            UIApplicationMain + 212
 SmartDragonAPP       main + 124
 libdyld.dylib        <redacted> + 4
)
Application_Active

the code where appens is

B4X:
'########## function active when the http result as a success ##########
Sub JobDone (jobName As HttpJob)

    'Dim tm As Cls_ToastMessage

    If jobName.Success = True Then
       
        Errore = 0
        GetData(jobName.GetString)

        If Errore  = 1 Then
            RetryExecuteQuery(jobName)
        End If
    Else
        'tm.Initialize("Job fail" & jobName.JobName,False)
        Log("ISS JOB Error: " & jobName.ErrorMessage)
'        ToastMessageShow("Error: " & job.ErrorMessage, True)
        Errore = 1
        RetryExecuteQuery(jobName)
    End If
   
    CallSub2(SourceTarget, "IISAPIDone" ,jobName.JobName)
   
    jobName.Release
   
    IIS_Busy = False
End Sub

'########## It excract 1 file Map with the data section of the json ##########
Sub GetData (Result As String)
   
    Dim Json As JSONParser
    Dim Map1 As Map

    Log("WebApi_RxData: = " & Result)
    Json.Initialize(Result)
    Map1 = Json.NextObject
    Data = Map1.Get("Data")
    If Map1.ContainsKey("Version") Then
        Log( Map1.Get("Version"))
       
        Dim a As JSONGenerator
       
        a.Initialize(Map1)
       
        Log(a.ToString)
           
    End If
    Dim MapError As Map = Map1.Get("NotTrappedError")
   
    Try
        If MapError.IsInitialized Then
            Dim MapNotTrapErr As Map = MapError.Get("Error")
            If MapNotTrapErr <> Null Then
                If MapNotTrapErr.IsInitialized Then
                    Log("WebAPI Error1: " & Map1.Get("NotAuthorized"))
                    Log("WebAPI Error2: " & Map1.Get("NotTrappedError"))
                    'set generic error type
                    Errore = 1
                       
                    Dim NotTrapErr As Map
                    NotTrapErr = Map1.Get("NotTrappedError")
                    'not trapped error catching and visualization

                End If
            End If
        End If
    Catch
        'Tm.Initialize("IIS Error decode NotTrapped",False)
        IIS_Busy = False
    End Try
   
    Try
        'check if there's a version compatibility error
        If Map1.Get("NotAuthorizedVersion") <> Null Then
            If Map1.Get("NotAuthorizedVersion") = True Then
                Errore = 4
            End If
        End If
    Catch
        Log("IIS Error Compatibility version")
        IIS_Busy = False
    End Try
   
    IIS_Busy = False
End Sub
 
Upvote 0

StxTeam

Member
Licensed User
I sniffed it with wireshark because i wasn't able to save and find in the iphone :(
 

Attachments

  • test_json.txt
    159.3 KB · Views: 229
Upvote 0
Top