我进入FATAL EXCEPTION: AsyncTask #2
我的doInBackground
:不要考虑String... urlActus
,因为我已经删除了这篇文章
protected Void doInBackground(String... urlActus) {
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
}
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
this.getWritableDatabase();
}
dbExist = checkDataBase();
if (!dbExist) {
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
private static String DB_NAME = "externalDB";
DB_PATH="/data/data"+context.getPackageName()+"/databases/";
private void copyDataBase() throws IOException{
InputStream myInput = myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName); //EROR LINE
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
我不明白为什么在doInBackground
我尝试构建时->OutputStream myOutput = new FileOutputStream(outFileName);
这是我的 LogCat 输出:
05-22 14:51:22.078: E/AndroidRuntime(8400): FATAL EXCEPTION: AsyncTask #2
05-22 14:51:22.078: E/AndroidRuntime(8400): java.lang.RuntimeException: An error occured while executing doInBackground()
05-22 14:51:22.078: E/AndroidRuntime(8400): at android.os.AsyncTask$3.done(AsyncTask.java:278)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-22 14:51:22.078: E/AndroidRuntime(8400): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.lang.Thread.run(Thread.java:856)
05-22 14:51:22.078: E/AndroidRuntime(8400): Caused by: java.lang.Error: Error copying database
05-22 14:51:22.078: E/AndroidRuntime(8400): at com.example.savingfiles.DatabaseHelper.createDataBase(DatabaseHelper.java:67)
05-22 14:51:22.078: E/AndroidRuntime(8400): at com.example.savingfiles.SplashActivity$Traitement.doInBackground(SplashActivity.java:81)
05-22 14:51:22.078: E/AndroidRuntime(8400): at com.example.savingfiles.SplashActivity$Traitement.doInBackground(SplashActivity.java:1)
05-22 14:51:22.078: E/AndroidRuntime(8400): at android.os.AsyncTask$2.call(AsyncTask.java:264)
05-22 14:51:22.078: E/AndroidRuntime(8400): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-22 14:51:22.078: E/AndroidRuntime(8400): ... 5 more
我有这个例外,我可以采取什么解决方案来避免这种情况?