语句: String src=contect.substring(contect.indexOf("src")+5,contect.indexOf("/>"))
content内容:免费实际生的一人姑地大真舒服夺大哥一大幅度圾百无一用一夺要 厅 震 在蛋一和 在仍在圾寻一三须脤 在不顾一切胡辱辱 在真舒服柘城夺 夺有&nbsp; 一一一有豕一有表知互利互惠拍胡一膨大圾在fe<br />
<img height="338" width="500" alt="" src="/bkzj/UserFiles/Image/ceshi(2).jpg" />

执行这一句时报错:java.lang.StringIndexOutOfBoundsException: String index out of range: -39
                  at java.lang.String.substring(Unknown Source)
          at blog.web.NoticeAction.saveNotice(NoticeAction.java:354)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
                  .........................

解决方案 »

  1.   

    我想是不是在<src  前的的<br/>的问题 这个/>可能导致的错误
      

  2.   

     String src=contect.substring(contect.indexOf("src")+5,contect.lastIndexOf("/>"));
    这样子看看
      

  3.   

    呵呵,这样肯定是不行的,因为我要的是图片的地址,这样如果最后有一个<br />,岂不是又出错........
      

  4.   

    String image = content.substring(content.indexOf("src")+5).substring(0, content.substring(content.indexOf("src")+5).indexOf("\"", 1));
    试试这样行不
      

  5.   

    用last啊,从最后一个/ 开始取值
      

  6.   


    int imgIndex = content.indexOf("img");
    if (imgIndex != -1) {
    imgIndex = content.indexOf("src", imgIndex);
    int endIndex = content.indexOf("\"", imgIndex + 5);
    System.out.println(content.substring(imgIndex + 5, endIndex));
    }
      

  7.   

    那你的也不正确呀,前面有个<br>呀。
    lastIndexOf("\"/>");
    这样我想就应该可以了吧