Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在设备上的CSV中找不到导出的SQLite DB_Android_Database_Sqlite_Csv_Export To Csv - Fatal编程技术网

Android 在设备上的CSV中找不到导出的SQLite DB

Android 在设备上的CSV中找不到导出的SQLite DB,android,database,sqlite,csv,export-to-csv,Android,Database,Sqlite,Csv,Export To Csv,我已经在我的应用程序中实现了一个SQLite表,现在想将它导出到设备本身中 我遵循了与此非常相似的代码: 这是: 然而,无论我如何修补,CSV文件都不会显示在我的设备上。我没有安装sd卡,但由于外部存储现在是模拟的,所以这不重要,对吗 导出方法: private void exportDB() { File dbFile = getDatabasePath("emotionSQLTable.db"); EmotionListDbHelper dbhelper = new E

我已经在我的应用程序中实现了一个SQLite表,现在想将它导出到设备本身中

我遵循了与此非常相似的代码:

这是:

然而,无论我如何修补,CSV文件都不会显示在我的设备上。我没有安装sd卡,但由于外部存储现在是模拟的,所以这不重要,对吗

导出方法:

private void exportDB() {

    File dbFile = getDatabasePath("emotionSQLTable.db");
    EmotionListDbHelper dbhelper = new EmotionListDbHelper(getApplicationContext());
    //switching out to internal directory here, for debu purposes and because we dont have sd card
    final String appPath = String.format
            (
                    "%s/Aletheia", Environment.getExternalStorageDirectory()
            );

    File exportDir = new File(appPath);
    if (!exportDir.exists()) {
        exportDir.mkdirs();
    }

    String fileName = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
    //TODO for debugging purposes
    File file = new File(exportDir, "emotionSQLTable.csv");
        try {
        file.createNewFile();
        CSVWriter csvWrite = new CSVWriter(new FileWriter(file));
        SQLiteDatabase db = dbhelper.getReadableDatabase();
            //Here we select from the TABLE NAME, which is emotionlist
        Cursor curCSV = db.rawQuery("SELECT * FROM emotionlist", null);
        csvWrite.writeNext(curCSV.getColumnNames());
        while (curCSV.moveToNext()) {
            //Which column you want to exprort
            String arrStr[] = {curCSV.getString(0), curCSV.getString(1), curCSV.getString(2)};
            csvWrite.writeNext(arrStr);
        }
        csvWrite.close();
        curCSV.close();
    } catch (Exception sqlEx) {
        Log.e("MainActivity", sqlEx.getMessage(), sqlEx);
    }


}
DBHelper类

public class EmotionListDbHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "emotionSQLTable.db";

private static final int DATABASE_VERSION = 1;

public EmotionListDbHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

public void onCreate(SQLiteDatabase sqLiteDatabase) {
    String SQL_CREATE_WAITLIST_TABLE = "CREATE TABLE emotionlist(_id INTEGER PRIMARY KEY AUTOINCREMENT, anger DOUBLE NOT NULL, contempt DOUBLE NOT NULL, disgust DOUBLE NOT NULL, fear DOUBLE NOT NULL, happiness DOUBLE NOT NULL, neutral DOUBLE NOT NULL, sadness DOUBLE NOT NULL, surprise DOUBLE NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);";
    sqLiteDatabase.execSQL("CREATE TABLE emotionlist(_id INTEGER PRIMARY KEY AUTOINCREMENT, anger DOUBLE NOT NULL, contempt DOUBLE NOT NULL, disgust DOUBLE NOT NULL, fear DOUBLE NOT NULL, happiness DOUBLE NOT NULL, neutral DOUBLE NOT NULL, sadness DOUBLE NOT NULL, surprise DOUBLE NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);");
}

public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
    sqLiteDatabase.execSQL("DROP TABLE IF EXISTS emotionlist");
    onCreate(sqLiteDatabase);
}

到目前为止,我已经尝试将代码移动到AsyncTask中,并将其存储在内部内存中,但没有任何效果。任何建议都将得到解决,这里的问题不是SQLite代码。这是一个按钮本身的错误。按钮根本没有调用该方法