安装应用时,复制数据库工作就好了。但是当我试图在onUpgrade中复制数据库时。应用程序崩溃,即使我在onPostExecute中将其留空。但数据库已成功复制,应用程序运行正常。请帮帮我。
LoginActivity
private void Readfiles()
{
var word = new Word.Application();
object miss = System.Reflection.Missing.Value;
object path = @"C:\Users\gd-08\Desktop\Маршруты движения (только первый вход и последний выход).rtf";
object readOnly = true;
var docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
//Processing all tables in the documents
var firstTable = docs.Tables[1];
var c = firstTable.Rows.Count;
foreach (Word.Row row in firstTable.Rows)
{
List<string> cellValues = new List<string>();
foreach (Word.Cell cell in row.Cells)
{
string cellContents = cell.Range.Text;
// add the cell contents to the array, but remove the strange termination character on the end of the data
cellValues.Add(cellContents.Remove(cellContents.Length - 1));
}
// the first row is the column header
//AddWordTableRow(cellValues);
}
docs.Close();
word.Quit();
}
}
DatabaseHelper
public class AsyncCopyDatabase extends AsyncTask<String, String, String> {
DatabaseHelper db;
ProgressDialog progress;
protected void onPreExecute(){
super.onPreExecute();
db = new DatabaseHelper(LoginActivity.this);
progress = new ProgressDialog(LoginActivity.this);
progress.setMessage("Preparing data. Please wait..");
progress.setCancelable(false);
progress.show();
}
@Override
protected String doInBackground(String... strings) {
//return null;
try {
db.createDatabase();
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
db.openDataBase();
return null;
}
@Override
protected void onPostExecute(String result) {
//Toast.makeText(LoginActivity.this, result, Toast.LENGTH_SHORT).show();
progress.dismiss();
}
}