Current position:  Home > Default > IndexOf problem

IndexOf problem

Time:November 30
Advertisement
Hi guys I did use this code to read the html file and it work fine but when i try to add the restriction to it
(indexOf) i do get problem as it gives "String index out of range: -1" error
i am trying to return the string between any ">" and "<" in the html file ,which exists in the html file,
tanks in advance
public String  viewpageBody(String newURLStr)
      try {
         URL example = new URL (newURLStr);
      BufferedReader in = new BufferedReader(
                              new InputStreamReader(
                              example.openStream()));
      String Nexthtml="";
      String inputLine="";
      int sstar=1;
      while ( ( inputLine != null ) && ( aborted == false ))
                    inputLine = in.readLine().toLowerCase();
                   if ( inputLine != null )
                                  {      System.out.println(inputLine);
                                       int star=      inputLine.indexOf( ">",sstar);
                                System.out.println(star);
                                int ref=       inputLine.indexOf("<",star);
                                 System.out.println(ref);
                                sstar=ref;
             String Bodyweb =      inputLine.substring( star,ref);
                         //     inputLine = stopWord( Bodyweb ); // do some manipulation
                         //      System.out.println(inputLine);
                                   Nexthtml += Bodyweb; // add up string
      in.close();
  return Nexthtml;   
       catch (Exception e) {
            System.out.println("File error: "+e);
     return "";                     
}
Advertisement
what are the results of your System.out.println's? If one of your index is -1 then a failure could happen...