You have created an array to hold tasks, but not actually put any tasks in it.
Therefore you have an array of { null, null, null, null, null, null, null, null, null, null}
In your first test you have
if (tasks[i] != null &&
so the rest of the if does not get evaluated.
Then it gets to the second one and tries to test what is actually in tasks[I]...but nothing is in there so it can't test it.