Reputation: 555
I'm trying to import all the data from the CSV file and overwrite those in the table in SQLite database. I have this method but I get error:
java.lang.IllegalArgumentException: Bad class: class java.lang.String
public void onClick(DialogInterface dialog, int which) {
File root = Environment.getExternalStorageDirectory();
File exportDir = new File(root.getAbsolutePath());
File csvFile = new File(exportDir,"myfile.csv");
try {
deleteTable();
ContentValues cv = new ContentValues();
CSVReader dataRead = new CSVReader(new FileReader(csvFile));
String[] vv = null;
while((vv = dataRead.readNext())!=null) {
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
String strDate = sdf.format( vv[0] );
cv.clear();
cv.put(Table.DATA,strDate);
cv.put(Table.A,vv[1]);
cv.put(Table.B,vv[2]);
cv.put(Table.C,vv[3]);
cv.put(Table.D,vv[4]);
SQLiteDatabase db = mHelper.getWritableDatabase();
db.insert(MyTable.TABLE_NAME,null,cv);
}
dataRead.close();
} catch (Exception e) {
}
}
Upvotes: 0
Views: 72
Reputation: 152807
String strDate = sdf.format( vv[0] );
You can't use SimpleDateFormat.format()
to format a String
.
Use format()
for converting Date
objects to String
s. Use parse()
to convert String
s to Date
objects.
Upvotes: 1