The piece of code above is a bit weird. See comments... The loop tries to iterate 15 times, inside which your if statement always increases the newLineCounter twice. And later on you are trying to access the array index based on the same newLineCounter.