I think i'm about ready to jump off a cliff. I've been trying to make preloaded sqlite databases to for bulk inserting purposes. No matter what my db files never open and the app crashes. finally i've tried to use the most idiot-proof method here, and i still come up short: https://github.com/jgilfelt/android-sqlite-asset-helper
Here's the pertaining logcat:
09-11 13:41:34.359: I/Database(2913): sqlite returned: error code = 14, msg = cannot open file at source line 25467
09-11 13:41:34.359: E/Database(2913): sqlite3_open_v2("/data/data/com.anthonyce.mcathomie/databases/northwind", &handle, 2, NULL) failed
09-11 13:41:34.369: W/SQLiteAssetHelper(2913): could not open database northwind - unable to open database file
09-11 13:41:34.369: W/SQLiteAssetHelper(2913): copying database from assets...
09-11 13:41:34.369: W/SQLiteAssetHelper(2913): extracting file: 'Northwind-v1.db'...
09-11 13:41:34.779: W/SQLiteAssetHelper(2913): database copy complete
09-11 13:41:34.869: I/SQLiteAssetHelper(2913): successfully opened database northwind
09-11 13:41:34.889: D/AndroidRuntime(2913): Shutting down VM
09-11 13:41:34.889: W/dalvikvm(2913): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-11 13:41:34.910: E/AndroidRuntime(2913): FATAL EXCEPTION: main
09-11 13:41:34.910: E/AndroidRuntime(2913): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anthonyce.mcathomie/com.anthonyce.mcathomie.GameActivity}: java.lang.ClassCastException: android.database.sqlite.SQLiteCursor
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.os.Handler.dispatchMessage(Handler.java:99)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.os.Looper.loop(Looper.java:123)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-11 13:41:34.910: E/AndroidRuntime(2913): at java.lang.reflect.Method.invokeNative(Native Method)
09-11 13:41:34.910: E/AndroidRuntime(2913): at java.lang.reflect.Method.invoke(Method.java:507)
09-11 13:41:34.910: E/AndroidRuntime(2913): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-11 13:41:34.910: E/AndroidRuntime(2913): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-11 13:41:34.910: E/AndroidRuntime(2913): at dalvik.system.NativeStart.main(Native Method)
09-11 13:41:34.910: E/AndroidRuntime(2913): Caused by: java.lang.ClassCastException: android.database.sqlite.SQLiteCursor
09-11 13:41:34.910: E/AndroidRuntime(2913): at com.anthonyce.mcathomie.GameActivity.onCreate(GameActivity.java:25)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-11 13:41:34.910: E/AndroidRuntime(2913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-11 13:41:34.910: E/AndroidRuntime(2913): ... 11 more
The code. i kid you not, I am using the same exact example file. I have been brought to my knees copying the sample step by step and i still get these fustrating errors.
public class McatDatabase extends SQLiteAssetHelper{
private static final String DB_NAME = "northwind";
private static final int DB_VERSION = 1;
private static final String[] COLUMNS = {"LastName"};
private static final String TABLE_NAME = "Employees";
public McatDatabase(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
public Cursor getQuestions() {
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.query(TABLE_NAME, COLUMNS, null, null, null, null, null);
c.moveToFirst();
return c;
}
}
In another class:
public class GameActivity extends Activity {
private McatDatabase db;
private Cursor thequestions;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
db = new McatDatabase(this);
thequestions = db.getQuestions();
TextView tv = (TextView)findViewById(R.id.TextView1);
tv.setText((CharSequence) thequestions);
thequestions.close();
db.close();
}
}