Reputation: 21
After storing data into sqlite database i need to retrieving that data and display. so for that i did like this.
private void display() {
// TODO Auto-generated method stub
try{
cursor2=database.query("patienttestdetails", new String[]{"date","sugarlevel"}, "pid="+patientId+"", null, null, null, "ptdid desc", "2");
if(cursor2.getCount()==0)
Toast.makeText(BloodsugarActivity.this, "Add Your Bloodsugar Details To See Here", Toast.LENGTH_LONG).show();
else
{
while(cursor2.moveToFirst())
{
bloodsugardetails=new TextView(this);
bloodsugardetails.setText(cursor2.getString(cursor2.getColumnIndex("date"))+" "+cursor2.getString(cursor2.getColumnIndex("sugarlevel")));
bloodsugardetails.setTextSize(20);
bloodsugardetails.setBackgroundResource(R.drawable.gray_view);
bloodsugardetails.setGravity(Gravity.FILL_HORIZONTAL);
layout.addView(bloodsugardetails);
}
}
cursor2.close();
database.close();
}
catch(Exception exception)
{}
}
My date base query is like this:
database.execSQL("create table if not exists patienttestdetails(ptdid integer primary key autoincrement,pid integer,date text,sugarlevel interger, FOREIGN KEY(pid) REFERENCES patientdetails(id))");
My database inserting is fine i checked the database. But while display, i am getting Java.lang.outofmemory error. My application have lot of XML files and lot of database operations. Before that all are fine i don't know why i am getting this error?
Logcat details:
https://docs.google.com/file/d/0B_c-SDSO63obZUdicVdDRWlKWXc/edit?usp=sharing
All advices are accepted
Thank you
SHANKAR
Upvotes: 0
Views: 626
Reputation: 641
You have an infinite loop there. Cursor.moveToFirst returns true if cursor has records (and yours apparently does).
http://developer.android.com/reference/android/database/Cursor.html
Change it to moveToNext()
EDIT: On a side note, doing DB access and UI update in the same thread (UI thread) is not recommended.
Upvotes: 2