0
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轉換標題錯誤,來源是分開的,首先一個逗號行正在讀取日期,第2,3和4行將連接到字段和休息價值請幫助。消息代碼:JAVA PLUGIN_1762消息:[錯誤] java.lang.IndexOutOfBoundsException:指數:37,尺寸:37

+0

看起來你的源文件有超過36個字段。你能檢查源文件嗎? – Samik

回答

0

將數組大小更改爲可以來自源文件的最大字段數(逗號+ 1的數量)。例如,如果最多有50個逗號,則將數組聲明更改爲:

String[] inInvoiceLine= new String [51]; 

如果沒有,的逗號是任意的,並且您無法確定事先會有多少人,您可以動態創建該數組而不指定其大小。您可以更改下面兩行

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

以下

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

這將動態創建數組,而不必擔心有多少逗號存在的源文件英寸

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.