Writing CSV file. myPackage.MyClass cannot be cast to java.lang.CharSequence -



Writing CSV file. myPackage.MyClass cannot be cast to java.lang.CharSequence -

i need write list<myclass> mylist csv file. in particular need write values. myclass has next implementation:

public class myclass { private object[] values; //... @override public string tostring() { string line = ""; (int i=0; i<this.getsize(); i++) { //if (this.values[i] != null) { line = line + this.values[i] + " "; //} } homecoming line; } }

the code following:

private void savesolutiontocsv(list<myclass> solution) { int columnsize = solution.get(0).getsize(); seek { filewriter author = new filewriter("test.csv"); iterator result = solution.iterator(); while(result.hasnext()) { for(int = 0; < columnsize; i++) { charsequence element = (charsequence)result.next(); writer.append(element); if(i < columnsize - 1) writer.append(','); } writer.append('\n'); } } catch(exception e) { e.printstacktrace(); } }

and error message following:

java.lang.classcastexception: mypackage.myclass cannot cast java.lang.charsequence

how solve problem? thx.

try:

string element = result.next().tostring(); writer.append(element); if(i < columnsize - 1) writer.append(',');

java csv charsequence

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -