0

I am having extreme difficulty in running this quiz application. The application uses a db file which is created in SQLite browser. I have a Database helper class from which I have added the path to the db.

I have also added the db file within the assets folder in my application. When I run the application I receive an unexpectedly error.

I can open the database within DDMS view and see the contents within data/data/mypackage/

When I debug this I receive an error message in Logcat and an activity thread opens which says source not found, Edit source look up Path:

I tried adding an image of log cat but I cannot do so yet.

I receive the following error:

sqlite returned: error code = 14, msg = cannot open file at source 25467 sqlite3_open_v2("/data/data/com.quiz.easy/database/quizzed", &handle, 1, NULL) failed

I have tried changing the paths within the Database helper class and the path changes but I'm not sure what is wrong.

The path within the database helper class:

public class DataBaseHelper extends SQLiteOpenHelper{

//The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.quiz.easy/databases/";
private static String DB_NAME = "quizzed";
private static String Table_name="Quiz";

I can upload all the source code if needed. I would appreciate any help with this as I am going in circles and have been trying to get this to work for a whole week.

Please help me. Thanks

Raj
  • 693
  • 4
  • 17
  • 29
  • Android applications don't use DBs from the "assets" folder. They don't typically use existing db files at all. You can use the assets folder to include a pre-built database file, but you'll need to programatically copy the db file to the correct location to use it via SQLiteOPenHelper. Are you doing the "copy" step? http://stackoverflow.com/questions/513084/how-to-ship-an-android-application-with-a-database – Charlie Collins Feb 08 '11 at 20:20
  • Thank you for your reply. I have created a database within sqlitebrowser using the following sql commands: CREATE TABLE Quiz(Correct_Answer TEXT, Quiz_ID INTEGER PRIMARY KEY, Quiz_Text TEXT) CREATE TABLE Answers(Answer TEXT, Answer_ID INTEGER PRIMARY KEY, Quiz_ID NUMERIC) CREATE TABLE Android_Metadata("locale" TEXT DEFAULT 'en_US') From there I have copied this file manually into assets and into data/data/mypackage/database . – Raj Feb 08 '11 at 20:26
  • When you say the copy step is that adding the filehelper class within the application. I have just added this and I still receive this error. Grateful for your help. – Raj Feb 08 '11 at 20:43
  • Here: **sqlite3_open_v2("/data/data/com.quiz.easy/database/quizzed", &handle, 1, NULL) failed** you use _database_ in your path, it should be _databases_. Perhaps just a typo after copy&paste, but would be worth checking out. – ldx Feb 08 '11 at 21:31
  • Thanks for your answer but it was a type after copy&paste in the application it is databases. Thanks again – Raj Feb 08 '11 at 21:45
  • You might want to try and add the file extension to your path: myDatabase.db – Austyn Mahoney Feb 08 '11 at 22:01
  • I have tried to add the file extension to the path but I still get the same error. The path updates in logcat as well, but it still gives a unexpected error. Thanks – Raj Feb 08 '11 at 22:07

2 Answers2

0

already bug raised in this link

http://code.google.com/p/android/issues/detail?id=949

use the following api...

context.openOrCreateDatabase("sample.db", MODE_PRIVATE, null);

try this link

http://www.itsalif.info/content/check-if-database-exist-android-sqlite3openv2-failed

shanethehat
  • 15,460
  • 11
  • 57
  • 87
satish
  • 27
  • 2
0

I am also having same problem sqlite3_open_v2 failed

but After searching on this problem I found this link and I modified my code according to this link and the modified code is look like this:

public boolean databaseExist()
{
    File dbFile = new File(DB_PATH + DB_NAME);
    return dbFile.exists();
}

hope this also helps in solve your problem. :)

Deepak
  • 1,989
  • 1
  • 18
  • 20