 <p>This is happening because you're calling <code>message+=</code> on a <code>null</code> string, so you're adding <code>currentLine</code> to null. </p> <p>Simplest fix would be to set <code>massage</code> to <code>""</code> when you initialise it: </p> <pre><code>String message = ""; //Rest of code... </code></pre>