我需要做的是在某个商店获取某个用户的积分,我运行它;
Cursor cursor1 = myDB.checkPointss(email, name);
String one = cursor1.getString(cursor1.getColumnIndex("POINTS"));
scanText.setText("barcode resueeeelt " + one);
这是方法;
public Cursor checkPointss(String email, String name) {
Cursor c = db.rawQuery("SELECT * FROM compdata WHERE EMAIL= ? AND NAME=?", new String[] {email, name});
if (c != null) {
c.moveToFirst();
}
return c;
}
每当我尝试登录页面时,它会因为试图获得积分而崩溃?我尝试了很多不同的代码,但似乎都没有。
所以我只想让它找到包含该用户名和商店名称的行的点,然后在点上添加一定数量并更新数据库。
02-18 20:07:42.694 15570-15570/com.adventorious.quickrewards E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.adventorious.quickrewards, PID: 15570
java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:439)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at com.adventorious.quickrewards.Scan$3.onPreviewFrame(Scan.java:155)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1016)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
这项工作;
public boolean checkPoints(String email, String name){
Cursor c = db.rawQuery("SELECT POINTS FROM compdata WHERE EMAIL= ? AND NAME=?", new String[] {email, name});
if(c.moveToFirst()) {
return true;
} else {
return false;
}
}
那为什么不能获取数据呢?
答案 0 :(得分:1)
getColumnIndex()
区分大小写,而SQL则不区分大小。
如果表中的列是小写的,它在SELECT *
结果集中将为小写,并且尝试使用大写列名称检索它将不起作用。