消息代码:JAVA PLUGIN_1762消息:[ERROR] java.lang.IndexOutOfBoundsException:Index:37,Size:37

时间:2016-05-12 18:20:05

标签: informatica informatica-powercenter informatica-powerexchange

String str1,str2,str3;
String[] inInvoiceLine= new String [36];
inInvoiceLine = Col1.split(","); 
if (rowNum == 1)
 {
   outInvStartDt = inInvoiceLine[0];
  outInvEndDt = inInvoiceLine[1]; 
} 
else if (rowNum == 2)
{
 for( int i = 0; i < inInvoiceLine.length - 1; i++)  
{
names.add(inInvoiceLine[i].trim());}}
else if( rowNum >= 3 && rowNum <= 4)
{
 for( int i = 0; i < inInvoiceLine.length - 1; i++)  
{
str1=(inInvoiceLine[i].trim());
str2=names.get(i);
str3=str2.concat(str1);
names.set(i,str3);
}
}
 else if( rowNum > 4 )
 {
    for( int i = 0; i < inInvoiceLine.length - 1; i++) 
{    
Invoice_Beg_Date=outInvStartDt ;
Invoice_End_date=outInvEndDt ;
      switch (i) 
{
        case 0:  outCarrier = inInvoiceLine[i].trim();
                 break;
        case 1:  outContract = inInvoiceLine[i].trim();
                 break;
        case 2:  outGroup = inInvoiceLine[i].trim();
                 break;
        default: outName = names.get(i);
                outValue = inInvoiceLine[i].trim();


                 generateRow();  the fixed columns.
                 break;
      }  

    } 
}
rowNum++;   

大家好,  我在java转换中得到标题错误,Source是逗号分隔,第一行是读取日期,第2,3行和第4行将连接字段并休息值请帮助。

2 个答案:

答案 0 :(得分:0)

将数组大小更改为可以来自源文件的最大字段数(逗号数+ 1)。例如,如果最多有50个逗号,则将数组声明更改为:

String[] inInvoiceLine= new String [51];

如果没有。逗号是任意的,你无法预先决定会有多少,你可以动态创建数组而不指定它的大小。您可以更改以下两行

String[] inInvoiceLine= new String [36];
inInvoiceLine = Col1.split(",");

以下

String[] inInvoiceLine = Col1.split(",");

这将动态创建数组,而不必担心源文件中存在多少逗号。

答案 1 :(得分:0)

It worked. but I have another question .in the above code if you see I am trimming and concatenating the fields.
example: for the rownum2,3 and 4 if the field names are like 'totalfeecount', I need to put the space between each word 'total fee count'. 
what I need to add in the above code to achieve this.

else if( rowNum >= 3 && rowNum <= 4)
{
 for( int i = 0; i < inInvoiceLine.length - 1; i++)  
{
str1=(inInvoiceLine[i].trim());
str2=names.get(i);
str3=str2.concat(str1);
names.set(i,str3);
}
I am guessing this is where i need to give the space option to get the o/p. please help.