简体   繁体   中英

Error copying database in Android, when running program on emulator

I have written a simple Android application that uses a sqlite database which is inside "assets" folder. I used the DataHelper class that it's DB_PATH is initialized as follows:

 private static String DB_PATH = "/data/data/program.proverb/databases/";

When I try to run it on my Galaxy S, it works fine, but when I try to run it on emulator, it shows the following error:

11-13 19:20:31.302: ERROR/AndroidRuntime(289): FATAL EXCEPTION: main
11-13 19:20:31.302: ERROR/AndroidRuntime(289): java.lang.Error: Error copying database

Would you please help me to solve this problem, so that it works on emulator too?

try
{
   copyDataBase();
} 
catch (IOException e)
{
      throw new Error("Error copying database");
}

Your answer is inside the IOException. You need to log the stack trace, or instead of throwing "Error", throw this:

throw new RuntimeException(e);

Android will grab the exception and log it for you. That should tell you at least where to start.

There are two likely candidates.

1) The database doesn't exist in the assets folder (or the name is slightly wrong). 2) You have the wrong path for your program folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM