String (capital S) concatenation in the way you do (in both applications) chews memory due to the creation of temporary String objects. Rather use += or concat().
There is also no need to concatenate; you can simply use a few print statements, it will achieve the same.
I do not know if this is the cause of the issue.