Follow Us
Contribute
  • Register
Errorbase is a collaborative writing project, that aims to build the largest trouble-shooting guide about all kinds of error messages.

Categories

0 votes

I believe I am getting an error message that is incorrect and I am looking for explanations/solutions please. Here is the code:

 

public static void Restart(ArrayList searched, ArrayList users)throws IOException{

FileReader file1 = new FileReader("searched.txt");

FileReader file2 = new FileReader("user_data.txt");

BufferedReader reader1 = new BufferedReader(file1);

BufferedReader reader2 = new BufferedReader(file2);

//String[] data = new String[2];

ArrayList entry;

ArrayList index;

String line = reader1.readLine();

while(line != null){

  searched.add(line);

  line = reader1.readLine();

}//while

file1.close();

reader1.close();

line = reader2.readLine();

while(line != null){

  //data[0]=line;

  entry = createList(line);

  line = reader2.readLine();

  //data[1] = line;

 

 

  index = createList3(line);

  boolean found = false;

  //System.out.println("size= "+users.size());

  for(int i=0; i< users.size(); i++){

  if(entry.get(0)==users.get(i).getID()){

  found = true;

  users.get(i).addTweet(entry.get(1),entry.get(2),index);

  i=users.size();

   }//if

  }//for

  if(!found){

 users.add(new user_loc(entry.get(0)));

 System.out.println(users.size());

 //int count = users.size();

 //System.out.println("int: "+count);

 users.get(users.size()-1).addTweet(entry.get(1),entry.get(2),index);

 //System.out.println("here 1");

 

  }//if

 

 

  entry.clear();

  index.clear();

  line = reader2.readLine();

}//while

file2.close();

reader2.close();

}//Restart

 
 
error message:
"1
2
3
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:546)
at java.util.ArrayList.get(ArrayList.java:321)
at avgLocation.Restart(avgLocation.java:195)
at avgLocation.main(avgLocation.java:28)"
 

BUT IT prints that the arrayList size is 3!!!

requested by

Please log in or register to to add a solution for this error.

...