3 Replies Latest reply: Dec 30, 2008 12:56 PM by 667847 RSS

    String index out of range - error

    807589
      I am trying to find the location an a website on the Internet with the Literals 'eLef'.
      import java.net.*;
      import java.io.*;
      
      public class MyURLReader3 {
          public static void main(String[] args) throws Exception {
              URL MyURL = new URL("http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&ssPageName=STRK:MEWAX:IT&item=160306336907");
              URLConnection MyU = MyURL.openConnection();
              BufferedReader in = new BufferedReader(
                                      new InputStreamReader(
                                      MyU.getInputStream()));
              String inputLine;
           Integer Laenge,Position;
           char Zeichen;
      
              while ((inputLine = in.readLine()) != null) {
               Laenge = inputLine.length();
               Position = 0;
      
                  System.out.print(inputLine.length()+" ------ ");
               while(Position < Laenge) {
                Zeichen = inputLine.charAt(Position); 
                if (Zeichen == 'e') { Position++; Zeichen = inputLine.charAt(Position); 
                     if (Zeichen == 'L') { Position++; Zeichen = inputLine.charAt(Position); 
                          if (Zeichen == 'e') { Position++; Zeichen = inputLine.charAt(Position); 
                               if (Zeichen == 'f') {System.out.println("JAK!!!"); System.out.println(inputLine+'-');}}}} 
                Position++;
                }
                  if (inputLine.length() != 0) System.out.println(inputLine.length()+" - "+inputLine.charAt(0)+"----");
                  else System.out.println(inputLine.length());
      }
      
              in.close();
          }
      }
      The programm gives out the size of each line until it comes to a line with 936 chars.
      Then it outputs a "String index out of range" - error.
      The line cannot be to big, since it handles lines with over 6000 chars just fine.
      The error occurs in Line 22, the one with the charAt Method.
      I have no idear what to do. Who can help me out?