2014-04-19 2 views
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) { 

} 
} 

답변

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

당신은 String의 형식을 SimpleDateFormat.format()을 사용할 수 없습니다.

개체를 String으로 변환하려면 format()을 사용하십시오. StringDate 개체로 변환하려면 parse()을 사용하십시오.