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++; 

Hallo zusammen, ich den Titel Fehler in Java-Transformation erhalten, Quelle ist eine durch Kommata getrennt, Erste Zeile liest die Daten, Zeile 2, 3 und 4 verketten die Felder und ruhen die Werte bitte helfen.Nachricht Code: JAVA PLUGIN_1762 Nachricht: [ERROR] java.lang.IndexOutOfBoundsException: Index: 37, Größe: 37

+0

Sieht aus wie Ihre Quelldatei mehr als 36 Felder hat. Könnten Sie die Quelldatei überprüfen? – Samik

Antwort

0

Ändern Sie die Array-Größe auf die maximale Anzahl der Felder (Anzahl der Kommas + 1), die aus der Quelldatei stammen können. Wenn zum Beispiel maximal 50 Kommas vorhanden sind, ändern Sie die Array-Deklaration wie folgt:

String[] inInvoiceLine= new String [51]; 

Wenn die Nr. Die Anzahl der Kommas ist beliebig, und Sie können nicht entscheiden, wie viele im Voraus kommen. Sie können das Array dynamisch erstellen, ohne seine Größe anzugeben. Sie können das Dies würde das Array dynamisch erstellen, ohne sich Sorgen zu machen, wie viele Kommas sind in der Quelldatei

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

an folgende

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

unter zwei Linien ändern.

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. 
Verwandte Themen