I don't understand why this method isn't working. It compiles, but throws a runtime error.
Here's the code. It's a Pig Latin-izer. It should split the phrase into words, then format those words, and then put them all back together in an ArrayList (I may change this later.) I don;t understand why this is not running correctly.
import java.util.*;
public class OinkerSpine 
{
    public ArrayList<String> pigLatin (String phrase)
    {
        phrase = phrase.replaceAll(".", " .");
        phrase = phrase.replaceAll(",", " ,");
        phrase = phrase.replaceAll("!", " !");
        //phrase = phrase.replaceAll("?", " ?");
        phrase = phrase.replaceAll("'", " '");
        String []words = phrase.split(" ");
        ArrayList <String> Endphrase = new ArrayList <String> ();
        final String AY = "ay";
        final String YAY = "-yay";
        String endword = "";
        for(int i=0; i < words.length; i++) 
        {
            String firstletter;
            String restofword;
            String secondletter;
            if (words[i].length() == 1)
            {
                firstletter = words[i];
                restofword = "";
            }
            else
            {
                firstletter = words[i].substring(0, 1);
                restofword = words[i].substring(1);
            }
            boolean firstIsUpper = (firstletter.equals(firstletter.toUpperCase()));
            if (firstIsUpper)
            {
                firstletter = firstletter.toLowerCase();
                secondletter = restofword.substring(0, 1);
                restofword = restofword.substring(1);
                secondletter = secondletter.toUpperCase();
                restofword = secondletter + restofword;
            }
            if (firstletter.equals("a") || firstletter.equals("e") ||
                firstletter.equals("i") || firstletter.equals("o") ||
                firstletter.equals("u"))
            {
                endword = firstletter + restofword + YAY;
            }
            else
            {
                endword = restofword + "-" + firstletter + AY;
            }
            endword = endword.replaceAll(" .", ".");
            endword = endword.replaceAll(" ,", ",");
            endword = endword.replaceAll(" !", "!");
            //endword = endword.replaceAll(" ?", "?");
            endword = endword.replaceAll(" '", "'");
            Endphrase.add(endword);
        }
        return Endphrase;
    }
}
What's up here?
 
     
    