Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write a list to CSV with Super CSV
    primarykey
    data
    text
    <pre><code>Exception in thread "main" org.supercsv.exception.SuperCsvException: The number of columns to be processed (229326) must match the number of CellProcessors (8): </code></pre> <p>I believe i may have to redo what im doing using supercsv as it may be easier in the long run however im open to any other suggestions. I simply want to write back to a csv file, i have a list with all the data in it however the ouput is like this</p> <pre><code>4350 02/06/2013 3965.21 0.0 0.0 0.0 0.0 0.0, 4698 02/06/2013 498.16 0.0 0.0 0.0 0.0 0.0, 4992 02/06/2013 97.87 87.82 6.05 0.0 0.0 0.0, 4441 02/06/2013 18.8 71.98 11.6 0.0 0.0 -42.5, 54092 02/06/2013 105.11 118.82 6.24 0.0 0.0 0.0, </code></pre> <p>I've managed to get the out put i want by replacing strings within the list however when it runs it hangs and i believe its due to how i'm writing back to the csv, i'm not sure, what else to do other than to write it back to the csv diffrently not using super csv. The error i get is</p> <pre><code>"1805","31/07/2013","-233.4","0.0","0.0","0.0","0.0","0.0" "8054","31/07/2013","280.45","82.38","52.38","0.0","0.0","-200.0"The number of columns to be processed (1) must match the number of CellProcessors (8): </code></pre> <p>My witer class is as follows</p> <pre><code>package writer; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.supercsv.cellprocessor.FmtDate; import org.supercsv.cellprocessor.ParseDouble; import org.supercsv.cellprocessor.ParseInt; import org.supercsv.cellprocessor.constraint.NotNull; import org.supercsv.cellprocessor.ift.CellProcessor; import org.supercsv.io.CsvListWriter; import org.supercsv.io.ICsvListWriter; import org.supercsv.prefs.CsvPreference; public class RentStatementsWriter { public ArrayList rData; private List&lt;String&gt; csvData; char b = ','; public RentStatementsWriter(ArrayList rentData) { rData = rentData; ICsvListWriter listWriter = null; try{ listWriter = new CsvListWriter(new FileWriter("rentl.csv"),CsvPreference.STANDARD_PREFERENCE); CellProcessor[] processors =new CellProcessor[]{ new ParseInt(), new FmtDate("dd/MM/yyyy"),// new ParseDouble(), new ParseDouble(), new ParseDouble(), new ParseDouble(), new ParseDouble(), new ParseDouble(), }; final String [] header = new String []{"_num", "End_Date", "bal_val","rval","cval","bf_val","aval","pval"}; System.out.print("to string "+rData.toString().replaceFirst(" ", "\"").replaceAll("\\,"," \\,").replaceAll(" ", "").replaceAll(" ", "\"\\,\"").replaceAll("\"\\,\"\\,", "\"\n\"")); csvData = Arrays.asList(rData.toString().replaceFirst(" ", "\"").replaceAll("\\,"," \\,").replaceAll(" ", "").replaceAll(" ", "\"\\,\"").replaceAll("\"\\,\"\\,", "\"\"")); /* * replace * .replaceAll(" ", "\"\\,\"") */ listWriter.writeHeader(header); listWriter.write(csvData, processors); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.print(e+" file unable to write"); } finally { if(listWriter !=null){ try { listWriter.close(); } catch (IOException e) { e.printStackTrace(); System.out.println("list writer"); } } } } String listToCsv(List&lt;String&gt; listOfStrings, char separator) { StringBuilder sb = new StringBuilder(); // all but last for(int i = 0; i &lt; listOfStrings.size() - 1 ; i++) { sb.append("\""+listOfStrings.get(i)+"\""); sb.append(separator); } // last string, no separator sb.append(listOfStrings.get(listOfStrings.size()-1)); return sb.toString(); } } </code></pre> <p>What am i missing in this syntax, or is there a better way of doing this task</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload