次
ContextWrapper cw =new ContextWrapper(getApplicationContext());
DB_PATH =cw.getFilesDir().getAbsolutePath()+ "/databases/"; //edited to databases
を使用して、データベースのパスを取得します。そして、あなたは
private void copyDataBase()
{
Log.i("Database",
"New database is being copied to device!");
byte[] buffer = new byte[1024];
OutputStream myOutput = null;
int length;
// Open your local db as the input stream
InputStream myInput = null;
try
{
myInput =myContext.getAssets().open(DB_NAME);
// transfer bytes from the inputfile to the
// outputfile
myOutput =new FileOutputStream(DB_PATH+ DB_NAME);
while((length = myInput.read(buffer)) > 0)
{
myOutput.write(buffer, 0, length);
}
myOutput.close();
myOutput.flush();
myInput.close();
Log.i("Database",
"New database has been copied to device!");
}
catch(IOException e)
{
e.printStackTrace();
}
}
この道を行くことができ、それは誤り 'java.lang.NullPointerExceptionが生成:仮想メソッドを呼び出そうとします" android.content.Context android.content.Context.getApplicationContext() 'nullのオブジェクト参照で' – Lily
ファイル名がHOSPITALS.dbのためDB_NAMEをHOSPITALSに変更しました – Lily
あなたはnullポインタの例外を取得している行ですか? –