Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 13th, 2012  |  syntax: None  |  size: 6.45 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. An error occured while executing doInBackground()
  2. @Override
  3. public void onClick(View v) {
  4.     case R.id.clockOut:
  5.  
  6.         /*if (WWActivity.this.isExternalStorageAvail()) {
  7.                new ExportDatabaseFileTask().execute();
  8.             } else {
  9.                Toast.makeText(WWActivity.this, "External storage is not available, unable to export data.",
  10.                         Toast.LENGTH_SHORT).show();
  11.             }*/
  12.  
  13.          if (WWActivity.this.isExternalStorageAvail()) {
  14.                new ExportDataAsXmlTask().execute("exampledb", "exampledata");
  15.             } else {
  16.                Toast.makeText(WWActivity.this, "External storage is not available, unable to export data.",
  17.                         Toast.LENGTH_SHORT).show();
  18.             }
  19.  
  20.  
  21.  
  22.         timer.open();
  23.         timer.saveTime(mName, mLat, mLon, mName, mName, mName, mName, mName);
  24.         timer.close();
  25.  
  26.         /*DatabaseAssistants DA = new DatabaseAssistants(myContext, mySQLiteDatabase);
  27.         DA.exportData();*/
  28.  
  29.         Intent stop = new Intent (WWActivity.this, SetTime.class);
  30.         stopService(stop);
  31.         break;
  32.     }
  33.  
  34.  
  35.  
  36. }
  37.  
  38. private boolean isExternalStorageAvail() {
  39.     // TODO Auto-generated method stub
  40.     return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
  41. }
  42.  
  43. private class ExportDataAsXmlTask extends AsyncTask<String, Void, String> {
  44.       private final ProgressDialog dialog = new ProgressDialog(WWActivity.this);
  45.  
  46.       // can use UI thread here
  47.       protected void onPreExecute() {
  48.          this.dialog.setMessage("Exporting database as XML...");
  49.  
  50.       }
  51.  
  52.       // automatically done on worker thread (separate from UI thread)
  53.       protected String doInBackground(final String... args) {
  54.          DataXmlExporter dm = new DataXmlExporter(WWActivity.this.application.getDataHelper().WWDatabaseHelper());
  55.          try {
  56.             String dbName = args[0];
  57.             String exportFileName = args[1];
  58.             dm.export(dbName, exportFileName);
  59.          } catch (IOException e) {
  60.             Log.e(MyApplication.APP_NAME, e.getMessage(), e);
  61.             return e.getMessage();
  62.          }
  63.          return null;
  64.       }
  65.  
  66.       // can use UI thread here
  67.       protected void onPostExecute(final String errMsg) {
  68.          if (this.dialog.isShowing()) {
  69.             this.dialog.dismiss();
  70.          }
  71.          if (errMsg == null) {
  72.             Toast.makeText(WWActivity.this, "Export successful!", Toast.LENGTH_SHORT).show();
  73.          } else {
  74.             Toast.makeText(WWActivity.this, "Export failed - " + errMsg, Toast.LENGTH_SHORT).show();
  75.          }
  76.       }
  77.    }
  78.  
  79.  private class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
  80.       private final ProgressDialog dialog = new ProgressDialog(WWActivity.this);
  81.  
  82.       // can use UI thread here
  83.       protected void onPreExecute() {
  84.          this.dialog.setMessage("Exporting database...");
  85.          this.dialog.show();
  86.       }
  87.  
  88.       // automatically done on worker thread (separate from UI thread)
  89.       protected Boolean doInBackground(final String... args) {
  90.  
  91.          File dbFile =
  92.                   new File(Environment.getDataDirectory() + "/data/com.totsp.androidexamples/databases/example");
  93.  
  94.          File exportDir = new File(Environment.getExternalStorageDirectory(), "exampledata");
  95.          if (!exportDir.exists()) {
  96.             exportDir.mkdirs();
  97.          }
  98.          File file = new File(exportDir, dbFile.getName());
  99.  
  100.          try {
  101.             file.createNewFile();
  102.             this.copyFile(dbFile, file);
  103.             return true;
  104.          } catch (IOException e) {
  105.             Log.e(MyApplication.APP_NAME, e.getMessage(), e);
  106.             return false;
  107.          }
  108.       }
  109.  
  110.       // can use UI thread here
  111.       protected void onPostExecute(final Boolean success) {
  112.          if (this.dialog.isShowing()) {
  113.             this.dialog.dismiss();
  114.          }
  115.          if (success) {
  116.             Toast.makeText(WWActivity.this, "Export successful!", Toast.LENGTH_SHORT).show();
  117.          } else {
  118.             Toast.makeText(WWActivity.this, "Export failed", Toast.LENGTH_SHORT).show();
  119.          }
  120.       }
  121.  
  122.       void copyFile(File src, File dst) throws IOException {
  123.          FileChannel inChannel = new FileInputStream(src).getChannel();
  124.          FileChannel outChannel = new FileOutputStream(dst).getChannel();
  125.          try {
  126.             inChannel.transferTo(0, inChannel.size(), outChannel);
  127.          } finally {
  128.             if (inChannel != null)
  129.                inChannel.close();
  130.             if (outChannel != null)
  131.                outChannel.close();
  132.          }
  133.       }
  134.  
  135.    }
  136.        
  137. 12-19 13:02:23.202: E/AndroidRuntime(1980): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
  138. 12-19 13:02:23.202: E/AndroidRuntime(1980): java.lang.RuntimeException: An error occured while executing doInBackground()
  139. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
  140. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  141. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  142. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  143. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  144. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
  145. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
  146. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.lang.Thread.run(Thread.java:1096)
  147.  12-19 13:02:23.202: E/AndroidRuntime(1980): Caused by: java.lang.NullPointerException
  148.  12-19 13:02:23.202: E/AndroidRuntime(1980):    at www.freshapp.com.wherewhen.html.WWActivity$ExportDataAsXmlTask.doInBackground(WWActivity.java:181)
  149. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at www.freshapp.com.wherewhen.html.WWActivity$ExportDataAsXmlTask.doInBackground(WWActivity.java:1)
  150. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
  151. 12-19 13:02:23.202: E/AndroidRuntime(1980):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  152. 12-19 13:02:23.202: E/AndroidRuntime(1980):     ... 4 more
  153.        
  154. DataXmlExporter dm = new DataXmlExporter(WWActivity.this.application.getDataHelper().WWDatabaseHelper());
  155.        
  156. WWActivity.this.application
  157. WWActivity.this.application.getDataHelper()
clone this paste RAW Paste Data