Android Cursor wont Loop, Application Freezes
<p>So here it goes, i have this application retrieves records from database, i have 5 entries from my database, and retrieved its using this code;</p>

<pre><code>Cursor c = dbconnection.rawQuery("SELECT * from Patients", null);
</code></pre>

<p>after that i looped it to retrieve the data pero row in my Database as such;</p>

<pre><code>c.moveToFirst();
while(!c.isAfterLast())
{
 //Some code to put records per column in to a Patient Object 
 c.moveToNext();
}
</code></pre>

<p>So my problem is that as it enters the loop my Emulator freezes and as i tried to display per record into a Log, i won't cuz the emulator it self already frozed.</p>

<p>Can somebody enlighten me into this matter, This issue is really really new to me</p>

<h2>EDIT</h2>

<p>yes already tried what baya and ofir suggested.. they worked out but i have this null error during iteration with this loop code</p>

<pre><code>Cursor c = dbHelper.retrieveAllData();

                c.moveToFirst();

                while(c.moveToNext())
                {
                    Log.d("dbcheck",Integer.toString(c.getPosition()));
                    //Log.d("dbcheck",c.getString(c.getColumnIndex("firstname")));
                    //Log.d("dbcheck",c.getString(c.getColumnIndex("lastname")));
                    **p.setFname(c.getString(c.getColumnIndex("firstname")));**
                    p.setMi(c.getString(c.getColumnIndex("middleinitial")));
                    p.setLname(c.getString(c.getColumnIndex("lastname")));
                    p.setAddr(c.getString(c.getColumnIndex("address")));
                    p.setAge(c.getInt(c.getColumnIndex("age")));
                    p.setMed_history(c.getString(c.getColumnIndex("med_history")));
                    p.setPat_status(c.getString(c.getColumnIndex("status")));
                    patientList.add(p);

                }
</code></pre>

<p>i have a null exception error on the p.setFname() line.. i don't know how it became null where in fact i already displayed it with Log using that code that is commented out..</p>
