2017-01-07 62 views
4

我需要從表中獲取所有數據逐行讀取0,0山坳,我用下面的代碼做同樣的SQLite中dbhelper類:java.lang.IllegalStateException:無法從CursorWindow

public Cursor getData() { 
     SQLiteDatabase db = this.getWritableDatabase(); 
     Cursor res = db.rawQuery("select * from " + PRODUCT_DETAILS_TABLE, null); 
     return res; 
    } 

以下列方式使用光標在我的活動現在我取數據:

public HashMap<String, ArrayList<CartModal>> getDatas() { 

      map = new HashMap<String, ArrayList<CartModal>>(); 
      stored_data = new ArrayList<CartModal>(); 
      Cursor cartdb = dbHelper.getData(); 
      if (cartdb != null && cartdb.getCount() > 0) { 
       if (cartdb.moveToFirst()) { 
        do { 
         String mloggedinuser = cartdb.getString(0); 
         String mname = cartdb.getString(1); 
         String email = cartdb.getString(2); 
         String mobile = cartdb.getString(3); 
         String about = cartdb.getString(4); 
         String pid = cartdb.getString(5); 
         String refnum = cartdb.getString(6); 
         String size = cartdb.getString(7); 
         String weight = cartdb.getString(8); 
         String price = cartdb.getString(9); 
         String catid = cartdb.getString(10); 
         String image = cartdb.getString(11); 

         CartModal cartarray = new CartModal(mloggedinuser, mname, email, mobile, about, pid, refnum, size, weight, price, catid, image); 
         stored_data.add(cartarray); 
         keys = mname; 
         map.put(mname, stored_data); 
        } while (cartdb.moveToPosition(stored_data.size())); 
        cartdb.close(); 
       } 
      } 
      return map; 
     } 

當我運行上面的程序我收到提示如下:

E/AndroidRuntime: FATAL EXCEPTION: main 
        Process: sdetech.io.brouchuretabproject, PID: 2434 
        java.lang.IllegalStateException: Couldn't read row 0, col 0 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:438) 
         at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51) 
         at sdetech.io.brouchuretabproject.Fragments.Cart.getDatas(Cart.java:58) 
         at sdetech.io.brouchuretabproject.Fragments.Cart.onCreateView(Cart.java:42) 
         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087) 
         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113) 
         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295) 
         at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801) 
         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682) 
         at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541) 
         at android.os.Handler.handleCallback(Handler.java:739) 
         at android.os.Handler.dispatchMessage(Handler.java:95) 
         at android.os.Looper.loop(Looper.java:148) 
         at android.app.ActivityThread.main(ActivityThread.java:5417) 
         at java.lang.reflect.Method.invoke(Native Method) 
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

我已經通過了很多解決方案在stackoverflow(android java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow),但沒有人幫助我解決這個問題。 請給我一個解決方案。

+0

'ListView'然後取出'getDatas'方法,只是使用'SimpleCursorAdapter' – pskink

+0

我無法找到任何邏輯錯誤的代碼,可能是你可以嘗試通過放置斷點來手動調試代碼,並查看出錯的地方。 –

+0

你只有'stored_data'的一個實例,並且你一次又一次地向這個實例添加新數據 – pskink

回答

0

我正在做的一切正確。但問題是,我是保存在db作爲base64 ecoded字符串的圖像。在獲取該數據時,它顯示非法exception.when我刪除該圖像,它完美的作品。 如果有人知道如何在sqlite中將base64編碼的圖像保存爲字符串,請回復以下。

三江源如果你想顯示在YHE數據

相關問題