android - Attempted to access a cursor after it has been closed -


i'm using following code delete image. works first time, when try capture image , delete staledataexception:

08-07 14:57:24.156: e/androidruntime(789): java.lang.runtimeexception: unable                       resume activity {com.example.cap_im/com.example.cap_im.mainactivity}:          android.database.staledataexception: attempted access cursor after has been closed. 

public void deleteimagefromgallery(string captureimageid) {     uri u = mediastore.images.media.external_content_uri;      getcontentresolver().delete(             mediastore.images.media.external_content_uri,             basecolumns._id + "=?", new string[] { captureimageid });      string[] projection = { mediastore.images.imagecolumns.size,             mediastore.images.imagecolumns.display_name,             mediastore.images.imagecolumns.data, basecolumns._id, };      log.i("infolog", "on activityresult uri u " + u.tostring());      try {         if (u != null) {             cursor = managedquery(u, projection, null, null, null);         }         if ((cursor != null) && (cursor.movetolast())) {              int = getcontentresolver().delete(mediastore.images.media.external_content_uri,                     basecolumns._id + "=" + cursor.getstring(3),   null);             log.v(tag, "number of column deleted : " + i);         }     } {         if (cursor != null) {             cursor.close();         }     } } 

function, managedquery() deprecated.

please use getcontentresolver().query().

the parameters same.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -