Shemil Shemil - 1 year ago 102
Android Question

ArrayIndexOutOfBound Exception in ArrayList Android Listview

i am doing a project to display contact details from a csv file. But, my arraylist is not accepting more than 25 values. it shows arrayindexoutofbound exception with lenth 3 and index 3. Here is my code..

ArrayList<Contact> arraylist = new ArrayList<>();
public void onCreate(Bundle savedInstanceState) {
// getting data from csv file
try {
InputStreamReader input_stream = new InputStreamReader(getAssets().open("test.csv"));
BufferedReader reader = new BufferedReader(input_stream);
String csv_item;
while ((csv_item = reader.readLine()) != null) {
String[] row = csv_item.split(",");
String col1 = row[0];
String col2 = row[1];
String col3 = row[2];
String col4 = row[3];
Contact wp = new Contact(col1, col2,
col3, col4);
// Binds all strings into an array
// namelist.add(col1);
// numberlist.add(col2);
// addresslist.add(col3);
// emaillist.add(col4);

}catch(ArrayIndexOutOfBoundsException ez){
catch(Exception ex) {

// Locate the ListView in listview_main.xml
list = (ListView) findViewById(;

Answer Source


Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.

Problem Arising from

        String col1 = row[0];
        String col2 = row[1];
        String col3 = row[2]; // Here is problem . Comment this line .Open your CSV and Check.
        String col4 = row[3]; 

Make sure, Your last two fields value exist or not .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download