The error message saying line 1762 is actually referring to the substring method in the String class. Your error is occurring on line 13.

Your loop goes while g is greater than or equal to 0....