1 2 Previous Next 17 Replies Latest reply: Mar 23, 2009 8:57 PM by 843789 RSS

    array list?

    843789
      what number does a list start on? or did i do something wrong here?
      import java.util.*;
      import java.io.*;
      import java.net.*;
      
      public class ServerHandler implements Runnable {
      
           public synchronized void run() {
                try {
                clients.clear();
      
                while(true){
                     if(clients.isEmpty()) continue;
      
                     for(int i = 0; i <= clients.size(); i++) {
      
                          BufferedReader br = new BufferedReader(new InputStreamReader(clients.get(i).getInputStream()));
                          String str = br.readLine();
      
                          for(int l = 0; l <= clients.size(); l++) {
                               BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(clients.get(l).getOutputStream()));
                               wr.write(str);
                               wr.flush();
                          }
                     }
                }
      
                } catch(Exception e) {
                     e.printStackTrace();
                }
           }
      
           public static List<Socket> clients = new ArrayList<Socket>();
      }
      that throws this,
      java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
              at java.util.ArrayList.RangeCheck(ArrayList.java:547)
              at java.util.ArrayList.get(ArrayList.java:322)
              at ServerHandler.run(ServerHandler.java:20)
              at java.lang.Thread.run(Thread.java:619)
        1 2 Previous Next