 <p>Array indices start from 0 and are upto [upperbound-1]. Since your loop starts at 0, it must end at &lt; the limit value rather than &lt;= limit value. So, change the "&lt;=" to "&lt;" in the loop. Eg:</p> <p>col &lt;= _maxColIndex</p> <p>should be changed to</p> <p>col &lt; _maxColIndex</p>