I have an error everytime I do a full search on a table that contains 8000+ records. This will continue to grow as time passes. I know that one person with in the right mind will never read each record (8000+ record). Nevertheless, there is always that person. For that reason, I do a full search. If there a way I can still do a full search but do it in pieces(displaying in chucks of X row and when it reach the bottom display the next chuck of rows? or even better increase the size as needed when it reach the cap on the memory? or any other method is welcome.
I get this error:
01-08 23:09:44.811: E/CursorWindow(327): need to grow: mSize = 1048576, size = 293, freeSpace() = 181, numRows = 2869
01-08 23:09:44.811: E/CursorWindow(327): not growing since there are already 2869 row(s), max size 1048576
01-08 23:09:44.811: E/Cursor(327): Failed allocating 293 bytes for text/blob at 2868,8
01-08 23:09:46.871: D/Cursor(327): finish_program_and_get_row_count row 4938
01-08 23:09:49.100: D/dalvikvm(327): GC_FOR_MALLOC freed 3290 objects / 214304 bytes in 123ms
01-08 23:09:53.370: D/dalvikvm(327): GC_FOR_MALLOC freed 62 objects / 13776 bytes in 603ms
01-08 23:10:05.131: D/Cursor(327): skip_rows row 2868
01-08 23:10:10.651: E/CursorWindow(327): need to grow: mSize = 1048576, size = 108, freeSpace() = 107, numRows = 2886
01-08 23:10:10.651: E/CursorWindow(327): not growing since there are already 2886 row(s), max size 1048576
01-08 23:10:10.661: E/CursorWindow(327): The row failed, so back out the new row accounting from allocRowSlot 2885
01-08 23:10:10.681: E/Cursor(327): Failed allocating fieldDir at startPos 2868 row 2885
01-08 23:10:12.641: D/Cursor(327): finish_program_and_get_row_count row 2053
01-08 23:10:14.071: D/dalvikvm(327): GC_FOR_MALLOC freed 6 objects / 9352 bytes in 271ms
01-08 23:10:20.962: D/dalvikvm(327): GC_FOR_MALLOC freed 4 objects / 34536 bytes in 224ms
01-08 23:10:29.001: D/Cursor(327): skip_rows row 5753
01-08 23:10:40.653: D/dalvikvm(327): GC_FOR_MALLOC freed 5 objects / 144 bytes in 331ms
Dont know how to solve this error. This error crashes my app in the first round(first time loading). After the it crashes, it goes to the main screen (activity) and I navigate to my search screen and preform a full search. It doesn't crash but the same error appears.
this is my activity that call the sql query that display the information in a custome listview:
public class zresultsearch extends ListActivity implements OnClickListener {
private YAOGetDataSource2 datasource;
private ListView recipesListView;
private TextView lblresultMainnametotalquantity;
public static String message;
public static String CardId;
public static String CardName;
public static String CardType;
public static String CardAttribute;
public static String CardLevelRank;
public static String CardSTType;
public static String CardAtk;
public static String CardDef;
public static String CardEffect;
public static String CardImage;
public static String CardSpic;
public static String CardLimit;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.zsearchresult);
datasource = new YAOGetDataSource2(this);
datasource.open();
general_search();
}
private void general_search(){
List<YAOYVD> values = datasource.SQLYVDTABLESEARCH();
//use custome listview adapter to assing into the custom adapter
// Create the adapter to convert the array to views
XCustomUsersAdapter adapter = new XCustomUsersAdapter(this, values);
recipesListView = (ListView)findViewById(R.id.lstcard);
recipesListView.setAdapter(adapter);
//retrive text and position from listview
recipesListView.setTextFilterEnabled(true);
recipesListView.setClickable(true);
recipesListView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
{
// ListView Clicked item index (the position)
int itemPosition = position;
TextView tvID = (TextView) v.findViewById(R.id.tvID);
TextView tvName = (TextView) v.findViewById(R.id.tvName);
TextView tvTYPE = (TextView) v.findViewById(R.id.tvTYPE);
TextView tvATTRIBUTE = (TextView) v.findViewById(R.id.tvATTRIBUTE);
TextView tvLEVELRANK = (TextView) v.findViewById(R.id.tvLEVELRANK);
TextView tvSTTYPE = (TextView) v.findViewById(R.id.tvSTTYPE);
TextView tvATK = (TextView) v.findViewById(R.id.tvATK);
TextView tvDEF = (TextView) v.findViewById(R.id.tvDEF);
TextView tvEFFECT = (TextView) v.findViewById(R.id.tvEFFECT);
TextView tvLimit = (TextView) v.findViewById(R.id.tvLimit);
TextView tvIMAGEidTXT = (TextView) v.findViewById(R.id.tvIMAGEidTXT);
TextView tvImageTXT = (TextView) v.findViewById(R.id.tvImageTXT);
CardId = tvID.getText().toString();
CardName = tvName.getText().toString();
CardType = tvTYPE.getText().toString();
CardAttribute = tvATTRIBUTE.getText().toString();
CardLevelRank = tvLEVELRANK.getText().toString();
CardSTType = tvSTTYPE.getText().toString();
CardAtk = tvATK.getText().toString();
CardDef = tvDEF.getText().toString();
CardEffect = tvEFFECT.getText().toString();
CardImage = tvIMAGEidTXT.getText().toString();
CardSpic = tvImageTXT.getText().toString();
CardLimit = tvLimit.getText().toString();
onClick(v);
}
});
lblresultMainnametotalquantity.setText("Total QTY : " + recipesListView.getCount() );
}
//@Override
public void onClick(View view) {
// TODO Auto-generated method stub
onPause();
onDestroy();
//define a new Intent for the second Activity
Intent intent = new Intent(this,zCardDetail.class);
//start the second Activity
this.startActivity(intent);
close();
}
//database open and close
@Override
protected void onResume() {
datasource.open();
super.onResume();
}
@Override
protected void onPause() {
datasource.close();
super.onPause();
}
@Override
protected void onDestroy(){
datasource.close();
super.onDestroy();
}
/*
* close the current windows/form
*/
public void close(){
finish();
//System.exit(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
the following is my datasource called YAOGetDataSource2:
public class YAOGetDataSource2 {
// Database fields
private SQLiteDatabase database;
private YAOMySQLiteHelper dbHelper;
//YVD TABLE
private String[] allColumnsYVD = { YAOMySQLiteHelper.COLUMNyvd_ID,
YAOMySQLiteHelper.COLUMNyvd_NAME ,
YAOMySQLiteHelper.COLUMNyvd_SETNUM ,
YAOMySQLiteHelper.COLUMNyvd_SET ,
YAOMySQLiteHelper.COLUMNyvd_TYPE ,
YAOMySQLiteHelper.COLUMNyvd_ATTRIBUTE,
YAOMySQLiteHelper.COLUMNyvd_LEVELRANK,
YAOMySQLiteHelper.COLUMNyvd_STTYPE,
YAOMySQLiteHelper.COLUMNyvd_ATK ,
YAOMySQLiteHelper.COLUMNyvd_DEF ,
YAOMySQLiteHelper.COLUMNyvd_EFFECT ,
YAOMySQLiteHelper.COLUMNyvd_IMAGE,
YAOMySQLiteHelper.COLUMNyvd_SPIC,
YAOMySQLiteHelper.COLUMNyvd_CARATTRIBUTEID,
YAOMySQLiteHelper.COLUMNyvd_MONSTERCATEGORYID,
YAOMySQLiteHelper.COLUMNyvd_MONSTERTYPEID,
YAOMySQLiteHelper.COLUMNyvd_SPELLCATEGORYID,
YAOMySQLiteHelper.COLUMNyvd_TRAPCATEGORYID,
YAOMySQLiteHelper.COLUMNyvd_CARDCATEGORYID,
YAOMySQLiteHelper.COLUMNyvd_CARDCATTYPE,
YAOMySQLiteHelper.COLUMNyvd_Anime,
YAOMySQLiteHelper.COLUMNyvd_animeid,
YAOMySQLiteHelper.COLUMNyvd_animeff,
YAOMySQLiteHelper.COLUMNyvd_AnimeNAme,
YAOMySQLiteHelper.COLUMNyvd_yvdname,
YAOMySQLiteHelper.COLUMNyvd_anime2,
YAOMySQLiteHelper.COLUMNyvd_errataString,
YAOMySQLiteHelper.COLUMNyvd_type2,
YAOMySQLiteHelper.COLUMNyvd_Limit
};
private YAOYVD cursorToCommentYVD(Cursor cursor) {
YAOYVD comment = new YAOYVD();
// comment.setRecNo_YAO(cursor.getLong(0));
// comment.setDECK_LIST_YAO(cursor.getString(1));
///add more columes to be display here
comment.setID_YAO(cursor.getLong(0));
comment.setNAME_YAO(cursor.getString(1));
comment.setTYPE_YAO(cursor.getString(2));
comment.setATTRIBUTE_YAO(cursor.getString(3));
comment.setLEVELRANK_YAO(cursor.getString(4));
comment.setSTTYPE_YAO(cursor.getString(5));
comment.setATK_YAO(cursor.getString(6));
comment.setDEF_YAO(cursor.getString(7));
comment.setEFFECT_YAO(cursor.getString(8));
comment.setIMAGE_YAO(cursor.getLong(9));
comment.setSPIC_YAO(cursor.getString(10));
comment.setLimit_YAO(cursor.getLong(11));
return comment;
}
// YVD NAME Table Seach general
public List<YAOYVD> SQLYVDTABLESEARCH() {
Log.i("Tag : List<YAOYVD> SQLYVDTABLESEARCH()", "getting ready to do the cursor query" );
String SQLYVD = "SELECT " +
YAOMySQLiteHelper.COLUMNyvd_ID + "," +
YAOMySQLiteHelper.COLUMNyvd_NAME +"," +
YAOMySQLiteHelper.COLUMNyvd_TYPE + "," +
YAOMySQLiteHelper.COLUMNyvd_ATTRIBUTE + "," +
YAOMySQLiteHelper.COLUMNyvd_LEVELRANK + "," +
YAOMySQLiteHelper.COLUMNyvd_STTYPE + "," +
YAOMySQLiteHelper.COLUMNyvd_ATK + "," +
YAOMySQLiteHelper.COLUMNyvd_DEF + "," +
YAOMySQLiteHelper.COLUMNyvd_EFFECT + "," +
YAOMySQLiteHelper.COLUMNyvd_IMAGE + "," +
YAOMySQLiteHelper.COLUMNyvd_SPIC + "," +
YAOMySQLiteHelper.COLUMNyvd_Limit +
" FROM "+ YAOMySQLiteHelper.TABLE_YVD +
" WHERE NAME not like '%token%' and NAME not like '%anime%'";
List<YAOYVD> comments = new ArrayList<YAOYVD>();
Cursor SQLYVDSEARCH = database.rawQuery(SQLYVD, null) ;
SQLYVDSEARCH.moveToFirst();
while (!SQLYVDSEARCH.isAfterLast()) {
YAOYVD comment = cursorToCommentYVD(SQLYVDSEARCH);
comments.add(comment);
SQLYVDSEARCH.moveToNext();
}
// make sure to close the cursor
SQLYVDSEARCH.close();
return comments;
}
}
0 comments:
Post a Comment