database problem wont work on real device
I have created a database file called questiondb
I am reading in the file with the code below
I used the DBAdapter class for my database.
{alex.android.development/alex.android.development.Basic_database_questionsA ctivity}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
try {
String destPath = "/data/data/" + getPackageName() + "/databases/QuestionDB";
File f = new File(destPath);
if (!f.exists()) {
System.out.println("where is the database file");
CopyDB( getBaseContext().getAssets().open("questiondb"),
new FileOutputStream(destPath));
}
} catch (FileNotFoundException e) {
Log.e(TAG, "message", e);
} catch (IOException e) {
Log.e(TAG, "message", e);
}
public void CopyDB(InputStream inputStream, OutputStream outputStream)
throws IOException {
//---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
|