The error is caused by this this part of your code:
When you type
You're setting the entire array to the last char you typed, which means the array is only 1 char long which gives you your exception when you try to access any index higher than that later on in your code.
Instead I suggest you use
Hope this helped