简体   繁体   中英

java.lang.IndexOutOfBoundsException in java

I have below java class where i am trying to import the data from CSV file and insert into oracle database table..

When i am trying to run this java class i am getting error as 'java.lang.IndexOutOfBoundsException'. I just try to see the insert statements using log.info("Insert values to table" +sql); and i can see some insert statement are generated and then its throwing an error.

I am quiet new to java so not sure how to handle this exception.

Below is my code:

I am not sure what line is causing the error - could you include the line number or your stack trace? However, this worries me:

for (int i = 0; i < headings.size(); i++) {
                String columnName = headings.get(i);
                String value = columns.get(i); // <- this

You are iterating with i through headings.size() , but what if headings.size() is greater than columns.size() ? Then your program will try to access an index of columns that does not exist, which would give you an IndexOutOfBounds exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM