0
我試圖從CSV文件導入所有數據並覆蓋SQLite數據庫中的表中的數據。我有這樣的方法,但我得到的錯誤:導入csv時出現Android錯誤
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) {
}
}