iOS Question Attempt to insert nil object from objects[2] error


Well-Known Member
Licensed User
Longtime User
I have a code that reads a row from a table in the database.
Let's say we have 2 fields with timestamps Start, Finish.

In some cases Finish doesn't have a timestamp and this field has NULL as a value.

My code
dim MySQL as String
dim Start as string,Finish as String,Schedule as String
dim rs as ResultSet

MySQL="SELECT Start,Finish from tblSchedule where id=?"
rs=SQL1.ExecuteQuery2(MySQL,Array as String(1))

Do While rs.NextRow



'I'm creating a parameters string that will be sent to the server with HttpJob
Schedule="Start=" & Start
Schedule=Schedule & "&Finish=" & Finish ' Here is problem string - line 19

Line 19 has a problerm. As I said in some cases Finish has a value NULL in the database and when I read it string Finish gets value <nil> so when I try to add it to the string Schedule it crashes with the error message -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2].

But if I put a breakpoint to line 19 or to any lines before and run the same code with the same values it doesn't crash. I tried 5 times - the same result.

Is it a bug? I'm using version 7.80.



B4X founder
Staff member
Licensed User
Longtime User
Nulls and strings don't play well together. Best to get rid of the null as soon as possible.

Something like:
MySQL="SELECT Start, IFNull(Finish, '') from tblSchedule where id=?"
Upvote 0