2014-01-24 22 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读取数据的代码。 –

相关问题