2014-01-24 23 views
0

我無法理解錯誤的含義是什麼?我將大量數據存儲到數據庫中動態存儲五個原始數據並刪除第一個原始數據後添加最新的第六個數據。我的代碼在Nexus 7.0和其他設備上工作正常,但在小設備或法律存儲設備中顯示錯誤。Android失敗爲文本/ blob分配223605字節爲4,2錯誤

錯誤

01-24 11:04:35.927: E/CursorWindow(30681): need to grow: mSize = 1048576, size = 340236, freeSpace() = 225346, numRows = 5 
01-24 11:04:35.927: E/CursorWindow(30681): not growing since there are already 5 row(s), max size 1048576 
01-24 11:04:35.927: E/Cursor(30681): Failed allocating 340236 bytes for text/blob at 4,2 

  //this is for reading the raw data from the database - updated 

databse = helper.getReadableDatabase(); 
Cursor cursor = databse.rawQuery("select * from comments where newspaper = " + newspaper,null); 
      String quantity_tb = null ; 
      try 
      {     
       while (cursor.moveToNext()) 
       { 
        String name_tb = cursor.getString(0); 
        String price_tb = cursor.getString(1); 
        quantity_tb = cursor.getString(2); 
         } 

      } 
      finally 
      { 
       if(cursor != null && !cursor.isClosed()){ 
         cursor.close(); 
        } 

       databse.close(); 
      }  
    //////////// 

      databse = helper.getReadableDatabase(); 
     Cursor cursor= databse.rawQuery("Select count(*) from comments;", null); 
     cursor.moveToFirst(); 
     int countdb= cursor.getInt(0); 
     cursor.close(); 
     databse.close(); 


     if (countdb == 5) 
     { 
      deletefirstraw(); 
     } 

     if (!masterData.isEmpty()) { 

      databse = helper.getWritableDatabase(); 
      ContentValues cv = new ContentValues(); 
      cv.put(helper.NEWSPAPER_NAME,masterData.get(0).newspaper);//name 
      cv.put(helper.NEWSPAPER_NEWS,json);// large data 
      databse.insert(helper.NEWSPAPER, null, cv); 
      databse.close(); 
     } 
    } 
} 

public void deletefirstraw() { 
    // TODO Auto-generated method stub 

      databse = helper.getWritableDatabase(); 
      Cursor cursor1 = databse.query(helper.NEWSPAPER, null, null, null, null, null, null); 
       if(cursor1.moveToFirst()) { 
        String rowId = cursor1.getString(cursor1.getColumnIndex(helper.COLUMN_ID)); 

        databse.delete(helper.NEWSPAPER, helper.COLUMN_ID + "=?", new String[]{rowId}); 
        } 
      cursor1.close(); 
     databse.close(); 

} 
+0

沒有你的代碼我們只能猜測它是由於缺少內存 –

+0

我加了我的代碼,顯示了我如何存儲和刪除第一個原始代碼。 –

回答

0

首先,有西港島線是相當大的性能損失與您kepp在打開和關閉您的數據庫。請保留一個操作集的引用。

其次,當關閉DB時,將其放入finally塊中以確保它被調用。

第三,如果沒有輸入if (!masterData.isEmpty()) {塊,那麼數據庫沒有關閉。

你也可以發佈更多的堆棧跟蹤,所以我們可以看到錯誤發生的地方。

+0

我添加了用於從db讀取數據的代碼。 –

相關問題