1 2 Previous Next 16 Replies Latest reply: Sep 19, 2006 1:27 AM by 807569 RSS

    how to correct exception ArrayIndexOutofBoundsException

    807569
      Hi All
      import java.io.*;
      import java.util.*;
      public class WordSearch {
      public static void main(String args[]) throws IOException {
           FileReader fr = new FileReader ("word.list");
           BufferedReader br = new BufferedReader(fr);
           String s;
           ArrayList a1 = new ArrayList(40000);
           ArrayList a2 = new ArrayList(20000);
           do
           {
                s=br.readLine();
                a1.add(s);
                char ch = s.charAt(1);
                if (ch == 'a'){
                     String nw = s.substring(2);
                     a2.add(nw);
      //           System.out.println(nw);
                }
                } while((s = br.readLine())!= null);
                fr.close();
      String ss[] = new String[a1.size()];
      String snw[] = new String[a2.size()];
      a1.toArray(ss);
      a2.toArray(snw);
      Arrays.sort(snw);
      for(int j = 0; j < a1.size(); j++)
      {
                     int x = Arrays.binarySearch(ss,snw[j]);
                     if ( x != ' ')
                     System.out.println(snw[x]);
      }

      }
      }
      Above is my code and when i am running, i am getting ArrayIndexOutofBoundsException. Please need your help experts.

      Sincerely
      Yogesh
        1 2 Previous Next