doInBackground中的java.lang.NullPointerException(final String ... args)

时间:2013-06-19 07:10:34

标签: android csv nullpointerexception android-sqlite

我有这个代码将.db文件转换为.csv并保存在我的android设备的sdcard中。不幸的是,活动停止并在doInBackground方法中导致java.lang.NullPointerException

protected Boolean doInBackground(final String... args) {
    File dbFile=getDatabasePath(logindatabaseadapter3.DATABASE_NAME);
    //  DbClass DBob = new DbClass(MyDatabaseActivity.this);
    File exportDir = new File(Environment.getExternalStorageDirectory(), "");
    if (!exportDir.exists()) {
        exportDir.mkdirs();
    }

    File file = new File(exportDir, "designtry.csv");

    try {
        file.createNewFile();
        CSVWriter csvWrite = new CSVWriter(new FileWriter(file));

        //SQLiteDatabase db = DBob.getReadableDatabase();
        Cursor curCSV=db.rawQuery("select * from " + Table_Name,null);
        //  Cursor curCSV = db.rawQuery("SELECT * FROM table_ans12",null);

        csvWrite.writeNext(curCSV.getColumnNames());

        while(curCSV.moveToNext()) {
            String arrStr[] ={curCSV.getString(0),curCSV.getString(1),curCSV.getString(2),curCSV.getString(3),curCSV.getString(4),
                    curCSV.getString(5),curCSV.getString(6),curCSV.getString(7),curCSV.getString(8),curCSV.getString(9),
                    curCSV.getString(10),curCSV.getString(11),curCSV.getString(12),curCSV.getString(13),curCSV.getString(14),
                    curCSV.getString(15),curCSV.getString(16),curCSV.getString(17),curCSV.getString(18),curCSV.getString(19)};


            csvWrite.writeNext(arrStr);

        }

        csvWrite.close();
        curCSV.close();
        return true;

    }

    catch(SQLException sqlEx) {
        Log.e("MainActivity", sqlEx.getMessage(), sqlEx);
        return false;
    }
    catch (IOException e) {
        Log.e("MainActivity", e.getMessage(), e);
        return false;
    }
}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,我只是将它放在错误的类中。