Database call crashes Android Application
- by Darren Murtagh
i am using a Android database and its set up but when i call in within an onClickListener and the app crashes
the code i am using is
mButton.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
s = WorkoutChoice.this.weight.getText().toString();
s2 = WorkoutChoice.this.height.getText().toString();
int w = Integer.parseInt(s);
double h = Double.parseDouble(s2);
double BMI = (w/h)/h;
t.setText(""+BMI);
long id = db.insertTitle("001", ""+days, ""+BMI);
Cursor c = db.getAllTitles();
if (c.moveToFirst())
{
do {
DisplayTitle(c);
} while (c.moveToNext());
}
}
});
and the log cat for when i run it is:
04-01 18:21:54.704: E/global(6333): Deprecated Thread methods are not supported.
04-01 18:21:54.704: E/global(6333): java.lang.UnsupportedOperationException
04-01 18:21:54.704: E/global(6333): at java.lang.VMThread.stop(VMThread.java:85)
04-01 18:21:54.704: E/global(6333): at java.lang.Thread.stop(Thread.java:1391)
04-01 18:21:54.704: E/global(6333): at java.lang.Thread.stop(Thread.java:1356)
04-01 18:21:54.704: E/global(6333): at com.b00348312.workout.Splashscreen$1.run(Splashscreen.java:42)
04-01 18:22:09.444: D/dalvikvm(6333): GC_FOR_MALLOC freed 4221 objects / 252640 bytes in 31ms
04-01 18:22:09.474: I/dalvikvm(6333): Total arena pages for JIT: 11
04-01 18:22:09.574: D/dalvikvm(6333): GC_FOR_MALLOC freed 1304 objects / 302920 bytes in 29ms
04-01 18:22:09.744: D/dalvikvm(6333): GC_FOR_MALLOC freed 2480 objects / 290848 bytes in 33ms
04-01 18:22:10.034: D/dalvikvm(6333): GC_FOR_MALLOC freed 6334 objects / 374152 bytes in 36ms
04-01 18:22:14.344: D/AndroidRuntime(6333): Shutting down VM
04-01 18:22:14.344: W/dalvikvm(6333): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
04-01 18:22:14.364: E/AndroidRuntime(6333): FATAL EXCEPTION: main
04-01 18:22:14.364: E/AndroidRuntime(6333): java.lang.IllegalStateException: database not open
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1567)
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1484)
04-01 18:22:14.364: E/AndroidRuntime(6333): at com.b00348312.workout.DataBaseHelper.insertTitle(DataBaseHelper.java:84)
04-01 18:22:14.364: E/AndroidRuntime(6333): at com.b00348312.workout.WorkoutChoice$3.onClick(WorkoutChoice.java:84)
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.view.View.performClick(View.java:2408)
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.view.View$PerformClick.run(View.java:8817)
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.os.Handler.handleCallback(Handler.java:587)
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.os.Handler.dispatchMessage(Handler.java:92)
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.os.Looper.loop(Looper.java:144)
04-01 18:22:14.364: E/AndroidRuntime(6333): at android.app.ActivityThread.main(ActivityThread.java:4937)
04-01 18:22:14.364: E/AndroidRuntime(6333): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 18:22:14.364: E/AndroidRuntime(6333): at java.lang.reflect.Method.invoke(Method.java:521)
04-01 18:22:14.364: E/AndroidRuntime(6333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-01 18:22:14.364: E/AndroidRuntime(6333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-01 18:22:14.364: E/AndroidRuntime(6333): at dalvik.system.NativeStart.main(Native Method)
i have notice errors when the application opens but i dont no what thet are from.
when i take out the statements to do with the database there is no errors and everthign runs smoothly