check your code, the maximum value for charAt() is str.length()-1, your x value is str.length()