-1
我需要做的是獲得特定商店中某個用戶的積分,我運行這個;從光標獲取數據
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;
}
}
那麼,爲什麼它不能獲取數據呢?
*我每次嘗試登錄到頁面,它崩潰* ..如果我在你身上,我會修復崩潰 – Blackbelt 2015-02-17 20:13:20
@Blackbelt因爲點而崩潰了?幫幫我? – 2015-02-17 20:14:41
我想怎麼知道它?你能發佈堆棧跟蹤嗎? – Blackbelt 2015-02-17 20:15:34