每次调用这个程序后,进别的函数,或者再做点别的什么,马上控制台就报
Method............: 100cdcd4 'java/lang/StringBuffer.expandCapacity
(virtual)'
然后程序就被迫中止了,在wtk环境下跑的
private void doNews(){
int maxnewsnum = 10;
String newstitle = new String("");
String[] newsElement = new String[maxnewsnum+1];
for (int j=0;j<newsElement.length;j++){
newsElement[j]="";
}
try{
newstitle = requestUsingPOST(newstitleURL,"");
}
catch(IOException e){
newstitle = "联机失败!";
}
System.out.println("newstitle: "+ newstitle);
int idx = newstitle.length();
int flag1 = 0;
int flag2 = 0;
int i = 0;
while ((flag2 < idx-8)&&(i<maxnewsnum))
{
flag1 = newstitle.indexOf("<Item>",flag2);
flag2 = newstitle.indexOf("</Item>",flag1);
newsElement[i] = newstitle.substring(flag1+6,flag2);
i++;
}
newsList = new List("新闻",List.IMPLICIT);
i=0;
while ((newsElement[i] != "")&&(i<maxnewsnum)){
newsList.append(newsElement[i],null);
i++;
}
newsElement = null;
newstitle = null;
newsList.addCommand(execCommand);
newsList.addCommand(commCommand);
newsList.addCommand(menuCommand);
newsList.setCommandListener(this);
currentScreen="新闻";
display.setCurrent(newsList);
}
经过两天多的排错,最后发现,出错的居然是System.out.println("newstitle: "+ newstitle);
这行语句,把这行注释掉后,再没有发现溢出,但是到现在也还不明白为什么控制台
输出也会导致溢出的错误呢?