简体   繁体   English

java中的java.lang.IndexOutOfBoundsException

[英]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..我有下面的java类,我试图从CSV文件导入数据并插入到oracle数据库表中..

When i am trying to run this java class i am getting error as 'java.lang.IndexOutOfBoundsException'.当我试图运行这个 java 类时,我收到了“java.lang.IndexOutOfBoundsException”的错误。 I just try to see the insert statements using log.info("Insert values to table" +sql);我只是尝试使用log.info("Insert values to table" +sql);查看插入语句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.我对 Java 很陌生,所以不确定如何处理这个异常。

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() ?您正在通过headings.size()使用i进行迭代,但是如果headings.size()大于columns.size()呢? Then your program will try to access an index of columns that does not exist, which would give you an IndexOutOfBounds exception.然后您的程序将尝试访问不存在的columns的索引,这会给您一个IndexOutOfBounds异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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