android - "Unable to open database file" when using SQLiteOpenHelper with instrumentation context -


i'm trying create database contains mock objects testing purposes. i'd prefer have db reside in test package instead of in application package.

protected class mockobjectopenhelper extends sqliteopenhelper {      mockobjectopenhelper() {         super(instrumentation.getcontext(), file_name, null, database_version);     }      @override     public void oncreate(sqlitedatabase db) {         ...     } } 

when create sqliteopenhelper within app, pass in instrumentation context path that's relative test package's database directory. think allow me create database in test package, doesn't seem case. "databases" directory never created in test package.

is there way have app create , access database resides in test project?

the exception:

14:50:13.917 pool-1-thread-1 android.database.sqlite.sqliteexception: unable open database file @ android.database.sqlite.sqlitedatabase.dbopen(native method) @ android.database.sqlite.sqlitedatabase.<init>(sqlitedatabase.java:1584) @ android.database.sqlite.sqlitedatabase.opendatabase(sqlitedatabase.java:638) @ android.database.sqlite.sqlitedatabase.openorcreatedatabase(sqlitedatabase.java:659) @ android.database.sqlite.sqlitedatabase.openorcreatedatabase(sqlitedatabase.java:652) @ android.app.applicationcontext.openorcreatedatabase(applicationcontext.java:482) @ android.database.sqlite.sqliteopenhelper.getwritabledatabase(sqliteopenhelper.java:98) @ com.myapp.test.http.dbmockhttpclient.createclientrequestdirector(dbmockhttpclient.java:52) @ com.myapp.test.http.universalmockhttpclient.createclientrequestdirector(universalmockhttpclient.java:42) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:539) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:487) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:465) e 

i had same issue. using application context did trick me:

this.getactivity().getapplicationcontext() 

instead of

instrumentation.getcontext() 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -