This question already has an answer here:
I'm trying to use my own Sqlite database in my android app here is my code
private void copyDataBase() throws IOException {
String outFileName = databasePath + databaseName+".db";
OutputStream myOutput = new FileOutputStream(myContext.getDatabasePath(databaseName).getAbsolutePath());
byte[] buffer = new byte[1024];
int i, r;
AssetManager am = myContext.getAssets();
String fn = String.format(databaseName);
InputStream is = am.open(databaseName);
while ((r = is.read(buffer)) != -1)
myOutput.write(buffer, 0, r);
is.close();
myOutput.flush();
myOutput.close();
}
But when I'm trying to test it its gives me null pointer exception Here is code of mine test class
public class DatabaseHelperTest {
@Test
public void DatabaseTest() throws Exception {
Context context = new MockContext();
DatabaseHelper db = new DatabaseHelper(context);
db.createDataBase();
assertEquals(db.getInfo(1), "Test");
}
}
Mine database file is in assets folder
Aucun commentaire:
Enregistrer un commentaire