An error occured while executing doInBackground() @Override public void onClick(View v) { case R.id.clockOut: /*if (WWActivity.this.isExternalStorageAvail()) { new ExportDatabaseFileTask().execute(); } else { Toast.makeText(WWActivity.this, "External storage is not available, unable to export data.", Toast.LENGTH_SHORT).show(); }*/ if (WWActivity.this.isExternalStorageAvail()) { new ExportDataAsXmlTask().execute("exampledb", "exampledata"); } else { Toast.makeText(WWActivity.this, "External storage is not available, unable to export data.", Toast.LENGTH_SHORT).show(); } timer.open(); timer.saveTime(mName, mLat, mLon, mName, mName, mName, mName, mName); timer.close(); /*DatabaseAssistants DA = new DatabaseAssistants(myContext, mySQLiteDatabase); DA.exportData();*/ Intent stop = new Intent (WWActivity.this, SetTime.class); stopService(stop); break; } } private boolean isExternalStorageAvail() { // TODO Auto-generated method stub return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); } private class ExportDataAsXmlTask extends AsyncTask { private final ProgressDialog dialog = new ProgressDialog(WWActivity.this); // can use UI thread here protected void onPreExecute() { this.dialog.setMessage("Exporting database as XML..."); } // automatically done on worker thread (separate from UI thread) protected String doInBackground(final String... args) { DataXmlExporter dm = new DataXmlExporter(WWActivity.this.application.getDataHelper().WWDatabaseHelper()); try { String dbName = args[0]; String exportFileName = args[1]; dm.export(dbName, exportFileName); } catch (IOException e) { Log.e(MyApplication.APP_NAME, e.getMessage(), e); return e.getMessage(); } return null; } // can use UI thread here protected void onPostExecute(final String errMsg) { if (this.dialog.isShowing()) { this.dialog.dismiss(); } if (errMsg == null) { Toast.makeText(WWActivity.this, "Export successful!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(WWActivity.this, "Export failed - " + errMsg, Toast.LENGTH_SHORT).show(); } } } private class ExportDatabaseFileTask extends AsyncTask { private final ProgressDialog dialog = new ProgressDialog(WWActivity.this); // can use UI thread here protected void onPreExecute() { this.dialog.setMessage("Exporting database..."); this.dialog.show(); } // automatically done on worker thread (separate from UI thread) protected Boolean doInBackground(final String... args) { File dbFile = new File(Environment.getDataDirectory() + "/data/com.totsp.androidexamples/databases/example"); File exportDir = new File(Environment.getExternalStorageDirectory(), "exampledata"); if (!exportDir.exists()) { exportDir.mkdirs(); } File file = new File(exportDir, dbFile.getName()); try { file.createNewFile(); this.copyFile(dbFile, file); return true; } catch (IOException e) { Log.e(MyApplication.APP_NAME, e.getMessage(), e); return false; } } // can use UI thread here protected void onPostExecute(final Boolean success) { if (this.dialog.isShowing()) { this.dialog.dismiss(); } if (success) { Toast.makeText(WWActivity.this, "Export successful!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(WWActivity.this, "Export failed", Toast.LENGTH_SHORT).show(); } } void copyFile(File src, File dst) throws IOException { FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new FileOutputStream(dst).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } } } 12-19 13:02:23.202: E/AndroidRuntime(1980): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception 12-19 13:02:23.202: E/AndroidRuntime(1980): java.lang.RuntimeException: An error occured while executing doInBackground() 12-19 13:02:23.202: E/AndroidRuntime(1980): at android.os.AsyncTask$3.done(AsyncTask.java:200) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.lang.Thread.run(Thread.java:1096) 12-19 13:02:23.202: E/AndroidRuntime(1980): Caused by: java.lang.NullPointerException 12-19 13:02:23.202: E/AndroidRuntime(1980): at www.freshapp.com.wherewhen.html.WWActivity$ExportDataAsXmlTask.doInBackground(WWActivity.java:181) 12-19 13:02:23.202: E/AndroidRuntime(1980): at www.freshapp.com.wherewhen.html.WWActivity$ExportDataAsXmlTask.doInBackground(WWActivity.java:1) 12-19 13:02:23.202: E/AndroidRuntime(1980): at android.os.AsyncTask$2.call(AsyncTask.java:185) 12-19 13:02:23.202: E/AndroidRuntime(1980): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 12-19 13:02:23.202: E/AndroidRuntime(1980): ... 4 more DataXmlExporter dm = new DataXmlExporter(WWActivity.this.application.getDataHelper().WWDatabaseHelper()); WWActivity.this.application WWActivity.this.application.getDataHelper()