程序为什么会出现这样的异常
//用while语句复制字符串
public class WhileDemo
{
public static void main(String[] args)
{
String copyFromMe="Copy this string until you encounter the etter'g'.";
StringBuffer copyToMe=new StringBuffer();
int i=0;
char c=copyToMe.charAt(i);
while(c!='g')
{
copyToMe.append(c);
c=copyFromMe.charAt(++i);
}
System.out.println (copyToMe);
}
}
请各位看看这段代码,编译运行说是有异常,请教分析一下!! 谢谢