1

I i found a way to access the Resources of the TestProject

Accessing resources in an android test project

but when i use the ActivityTestCase instead of AndroidTestcase i cannot access the database

java.lang.NullPointerException
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.j256.ormlite.android.AndroidConnectionSource.getReadWriteConnection(AndroidConnectionSource.java:66)
at com.j256.ormlite.android.AndroidConnectionSource.getReadOnlyConnection(AndroidConnectionSource.java:54)
at com.j256.ormlite.dao.BaseDaoImpl.idExists(BaseDaoImpl.java:805)
at com.j256.ormlite.dao.BaseDaoImpl.createOrUpdate(BaseDaoImpl.java:335)

is there a way to have both?

Community
  • 1
  • 1
wutzebaer
  • 14,365
  • 19
  • 99
  • 170

1 Answers1

0

Ok i solved my Problem:

i use now InstrumentationTestCase (i think ActivityTestCase would work either)

The Problem was that there are two contexts

    Context mainProjectContext = getInstrumentation().getTargetContext();
    Context testProjectContext = getInstrumentation().getContext();

now i can gat the resources from testProjectContext and let the database run with mainProjectContext

wutzebaer
  • 14,365
  • 19
  • 99
  • 170