Getting error "String index out of range: 0" on using String Builder
<p>So this is my code in Java (for returning two halves of a string - one is the odd half, starting with the index 0, or the first character, and the second half, starting with the index 1, or the second character):</p>

<pre><code>public class StringTest{
     public String halfOfString(String message, int start){
            int length = message.length();
            StringBuilder output = new StringBuilder(length); 
            char ch;
            int i;
            if((start==0)||(start==1)){
               for(i=start; i&lt;message.length(); i=i+2){
                            ch = message.charAt(i);
                            output.setCharAt(i,ch); // error occurs here
               }

            }
     return output.toString();
     }

     public void testFunction(){
           String s = "My name is Sid";
           String first = halfOfString(s, 0);
           String second = halfOfString(s, 1);
           System.out.println("First half is " + first + " and second half is " + second);
     }
}
</code></pre>

<p>So my problem is - whenever I attempt to run this program on BlueJ IDE, it doesn't, and returns the error in the title, on the line mentioned in the comment.</p>

<p>I have poured over this site for a similar question which may help me with my error, but all I found was a question which suggested a change I have already implemented (in the StringBuilder setCharAt method, the person had reversed the i and ch parameters).</p>

<p>Is it anything to do with the fact that the "output" is declared empty at first, and the setCharAt method can only replace the characters which already exist? 
Any help would be greatly appreciated.</p>