iOS Question [Solved] Attempted to insert nil object - File.Exists

hatzisn

Expert
Licensed User
Longtime User
Hi everyone,

I have this problem. I have created a class which is named RuntimePermissions in order to create a sub GetSafeDirDefaultExternal(Folder as String). The class is the following:

B4X:
Sub Class_Globals
 
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
 
End Sub

Public Sub GetSafeDirDefaultExternal(Folder As String) As String
 
    Log(File.DirDocuments & Folder)
    If Folder <> "" Then
'        If File.Exists(File.DirDocuments & Folder, "") = False Then
'            File.MakeDir(File.DirDocuments, Folder)
'        End If
        Return File.DirDocuments & Folder
    Else
        Return File.DirDocuments
    End If
 
 
End Sub


I define this class in the code module/page and call it with this code:

B4X:
    If File.Exists(rp.GetSafeDirDefaultExternal("Guide"),"") = False Then
        File.MakeDir(rp.GetSafeDirDefaultExternal(""), "Guide")
    End If

The "If File.Exists...." code starts at line 537. When I run the code directly I get the following error:

Application_Start
Error occurred on line: 537 (Main)
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]
Stack Trace: (
CoreFoundation <redacted> + 252
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation _CFArgv + 0
CoreFoundation <redacted> + 284
CoreFoundation <redacted> + 52
Trial App -[B4IFile Combine::] + 184
Trial App -[B4IFile Exists::] + 216
Trial App -[ResumableSub_main_RunFromActivityCreate resume::] + 672
Trial App -[b4i_main _runfromactivitycreate] + 368
Trial App -[ResumableSub_main_CheckIfActivationIsStillActive resume::] + 7128
Trial App -[b4i_main _checkifactivationisstillactive] + 368
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
Trial App +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
Trial App -[B4IShell runMethod:] + 448
Trial App -[B4IShell raiseEventImpl:method:args::] + 2172
Trial App -[B4IShellBI raiseEvent:eventarams:] + 1580
Trial App +[B4IDebug delegate:::] + 80
Trial App -[b4i_main _activity_create:] + 360
Trial App -[b4i_main _application_start:] + 1748
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
Trial App +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
Trial App -[B4IShell runMethod:] + 448
Trial App -[B4IShell raiseEventImpl:method:args::] + 2172
Trial App -[B4IShellBI raiseEvent:eventarams:] + 1580
Trial App __33-[B4I raiseUIEvent:eventarams:]_block_invoke + 60
libdispatch.dylib <redacted> + 24
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 1068
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 1924
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 104
UIKitCore UIApplicationMain + 212
Trial App main + 124
libdyld.dylib <redacted> + 4
)

Application_Active

On the contrary when I run the same code with a breakpoint in this line and step into this code it works perfect. Any suggestions anyone?

Thanks in advance
 
Last edited:

hatzisn

Expert
Licensed User
Longtime User
Strangely if I add a
B4X:
Sleep(400)
command it works perfect...
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Not working again after a clean project. Same error...
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Hi Erel, can you write to me with a private message your e-mail to send you the code so far. I do not want to post it here.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Never mind I will try to create a new project and send it here.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
I just figured out that working hours must have limits because if you go way too far with it, mistakes pop up like pop corns.
It seems that I forgot to initialize the class but I cannot understand since I did not initialize it how did it work with the Breakpoint and F8?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…