首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java.lang.StringIndexOutOfBoundsException: String index out of range: -1错误

2012-12-25 
java.lang.StringIndexOutOfBoundsException: String index out of range: -1异常点击右边红色标题查看本

java.lang.StringIndexOutOfBoundsException: String index out of range: -1异常
点击右边红色标题查看本文完整版:java.lang.StringIndexOutOfBoundsException: String index out of range: -1异常

java.lang.StringIndexOutOfBoundsException: String index out of range: -1

出现这个问题,在eclipse里指出出错的行数,可是我不知道为什么出错,我用的是substring函数,参数的beginIndex为一个html文件中一个字符串的位置

String content3 = content.substring(content.indexOf( " <head "));

提示是这一行出错,可是我不知道错误在哪?怎么解决呢?



------解决方法--------------------
String content3 = null;
int pos = content.indexOf( " <head ");
if (pos > -1) content3 = content.substring(pos);

    

热点排行