0

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) {

}
 }

1 Answer 1

1
String strDate = sdf.format( vv[0] );

You can't use SimpleDateFormat.format() to format a String.

Use format() for converting Date objects to Strings. Use parse() to convert Strings to Date objects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.