I always do like this:

MediaDbAdapter mDbHelper = null;
Cursor c = null;

try {
  // Do you DB stuff
} catch( Exception e) {
  // Something went wrong
}

// Close and cleanup
if ( c != null )
{
  // You do not need to deactivate the cursor
  c.close();
}
if(mDbHelper != null && mDbHelper.isOpen())
{
  mDbHelper.close();
}

On Jun 17, 10:31 pm, gcstang <[email protected]> wrote:
> I've followed the try/finally approach but still get this error.
>
> Is there anything else that can be done?
>
> Here is what I have.
>
> MediaDbAdapter mDbHelper = null;
> Cursor c = null;
> try {
>         mDbHelper = new MediaDbAdapter(ctxt);
>         mDbHelper.open();
>         c = mDbHelper.findByX(data.getX());
>         if(c != null) {
>            //Do an Update on the database
>         }
>         else if(c == null) {
>           //Do an Insert on the database
>         }} finally {
>
>                         if(c != null) {
>                                 c.deactivate();
>                                 c.close();
>                                 c = null;
>                         }
>                         if(mDbHelper != null && mDbHelper.isOpen()) {
>                                 mDbHelper.close();
>                         }
>                 }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to