在以下程序代码CursorIndexOutofBoundexception
中,运行应用程序时,logcat 中会显示 a。请给我一个解决方案。
public String getContact(String datevalue,String Userselectvalue) {
String selection = classdbOpenHelper.KEY_DESC + " = 'Userselectvalue'"
+" AND " + classdbOpenHelper.KEY_DATE + " = 'datevalue'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(classdbOpenHelper.DATABASE_TABLE,
new String[] {classdbOpenHelper.KEY_EVENT }, selection,
null, null, null, null);
String place = cursor.getString( );
return place;
}
日志猫:
08-05 11:21:13.327: E/AndroidRuntime(827): FATAL EXCEPTION: main
08-05 11:21:13.327: E/AndroidRuntime(827): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
08-05 11:21:13.327: E/AndroidRuntime(827): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
08-05 11:21:13.327: E/AndroidRuntime(827): at example.showevent1.classdbOpenHelper.getContact(classdbOpenHelper.java:59)
08-05 11:21:13.327: E/AndroidRuntime(827): at example.showevent1.FirstActivity$getclicker.onClick(FirstActivity.java:163)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.view.View.performClick(View.java:4204)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.view.View$PerformClick.run(View.java:17355)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.os.Handler.handleCallback(Handler.java:725)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.os.Handler.dispatchMessage(Handler.java:92)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.os.Looper.loop(Looper.java:137)
08-05 11:21:13.327: E/AndroidRuntime(827): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-05 11:21:13.327: E/AndroidRuntime(827): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 11:21:13.327: E/AndroidRuntime(827): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 11:21:13.327: E/AndroidRuntime(827): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-05 11:21:13.327: E/AndroidRuntime(827): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-05 11:21:13.327: E/AndroidRuntime(827): at dalvik.system.NativeStart.main(Native Method)