Unable to use getInt() but able to use getString() for a sqlite database
- by mwrazam
I am using a cursor to access a sqlite database I have in my app.
I am having trouble using the .getInt() on my database. My database is pre-created, and I have a few cursors that perform queries to interface with the information. Several of the columns in one of the tables are set as INTEGER type. I realize that sqlite has no built in check to make sure columns are indeed INT. However, when retrieving the data, I can use the .getString() function without any issues, but calling .getInt() causes the app to crash. Below is the relevant code. If I am missing anything, please let me know, and I'll add it in.
Any help is greatly appreciated. Thank you very much.
Cursor:
public Cursor getSkitStats(int module, int skit) {
Cursor mCursor = myDataBase.rawQuery("SELECT * FROM score WHERE mod="+module+" AND skit="+skit+"", null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
and I am using a simple Toast call to output the result of the query:
Toast.makeText(getApplicationContext(), scoreContent.getInt(0), Toast.LENGTH_SHORT).show();
The variable scoreContent is the cursor.
And here is the crash output:
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.os.Looper.loop(Looper.java:130)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.app.ActivityThread.main(ActivityThread.java:3701)
07-08 23:53:31.726: E/AndroidRuntime(15685): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 23:53:31.726: E/AndroidRuntime(15685): at java.lang.reflect.Method.invoke(Method.java:507)
07-08 23:53:31.726: E/AndroidRuntime(15685): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
07-08 23:53:31.726: E/AndroidRuntime(15685): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
07-08 23:53:31.726: E/AndroidRuntime(15685): at dalvik.system.NativeStart.main(Native Method)
07-08 23:53:31.726: E/AndroidRuntime(15685): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.content.res.Resources.getText(Resources.java:205)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.widget.Toast.makeText(Toast.java:258)
07-08 23:53:31.726: E/AndroidRuntime(15685): at jp.atomicideas.ne.Summary.onCreate(Summary.java:90)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-08 23:53:31.726: E/AndroidRuntime(15685): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
07-08 23:53:31.726: E/AndroidRuntime(15685): ... 11 more