4

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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Farid Ala
  • 668
  • 1
  • 12
  • 30
  • I imagine this has to do with the configured storage space of your emulator however, I think you should post some code as I don't think there is any standard class called DataHelper. So this behavior could be just a bug or misuse of that utility. – Greg Giacovelli Nov 13 '11 at 16:39
  • Dear Greg, thanks for your reply. My DataHelper class is copied from http://stackoverflow.com/questions/4768984/cant-open-database-android . Sorry, stackoverflow, does not let me send "new answer" to this thread, within 5 hours, so I had to use that URL. – Farid Ala Nov 13 '11 at 18:08

1 Answers1

6
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.

Kevin Galligan
  • 16,159
  • 5
  • 42
  • 62