×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    27

    Cannot Delete RecordStore although RecordStore is closed already

    Hi... my class has 2 methods which 1 of them saves image to RecordStore and the other one loads the saved image from RecordStore. In some conditions, some of the saved images need to be deleted from the RecordStore.
    Well, i keep getting "javax.microedition.rms.RecordStoreException: deleteRecordStore error: record store is still open". I'm pretty sure i have closed the RecordStore but it just can't be deleted.
    Below is the excerpt of my code. Since my original code is very long, i just enter the 3 relevant methods. Please kindly help.

    //A function to load image from the memory
    public Image LoadImage(int width, int height, String imageCid) throws RecordStoreException {
    rs = RecordStore.openRecordStore(imageCid, true);

    byte[] b = null;
    String imagename = null;
    Image image = null;

    if (rs.getNumRecords() > 0) {

    try {

    int i = rs.getNumRecords();

    for(int j = 1; j < i + 1; j++) {

    if(rs.getRecord(j) != null) {

    b = rs.getRecord(j);
    ByteArrayInputStream bin =
    new ByteArrayInputStream( b );

    DataInputStream din = new DataInputStream( bin );

    imageCid = din.readUTF();
    int remaining =
    (b.length-imageCid.getBytes().length-2)/4;

    int[] rawdata = new int[remaining];

    for(int k =0 ;k<rawdata.length ;k++) {
    rawdata[k] = din.readInt();
    }

    image = Image.createRGBImage(rawdata,
    width, height, false);

    bin.reset();
    din.close();
    din =null;
    }
    }
    } catch (IOException e) {

    e.printStackTrace();

    } catch(RecordStoreException recordstoreexception) {

    recordstoreexception.printStackTrace();

    }
    finally {
    System.out.println("Banner LoadImage - closing RecordStore of " + imageCid);
    rs.closeRecordStore();
    rs = null;


    }
    }
    return image;
    }

    //A function to save image to the memory of the device
    public boolean SaveImage (Image img, int width,
    int height, String imageCid) throws RecordStoreException {
    rs = RecordStore.openRecordStore(imageCid, true);

    if (img == null || width < 0 || height < 0 || imageCid == null) {

    throw new IllegalArgumentException("Check arguments");

    }

    int[] imgRgbData = new int[width * height];

    try {

    img.getRGB(imgRgbData, 0, width, 0, 0, width, height);

    } catch (Exception e) {
    // Problem getting image RGB data
    return false;
    }
    try {
    // Write image data to output stream (in order to get
    // the record bytes in needed form)
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeUTF(imageCid);

    for (int i = 0; i < imgRgbData.length; i++) {
    dos.writeInt(imgRgbData[i]);
    }

    // Open record store, create if it doesn't exist
    rs.addRecord(baos.toByteArray(), 0,
    baos.toByteArray().length); // Add record

    } catch (RecordStoreNotFoundException rsnfe) {
    // Record storage not found
    System.out.println("Banner SaveImage - RecordStoreNotFound");
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);

    rs.closeRecordStore();
    rs = null;

    return false;
    } catch (RecordStoreException rse) {
    // Other record storage problem
    System.out.println("Banner SaveImage - RecordStoreNotException");
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);

    rs.closeRecordStore();
    rs = null;

    return false;
    } catch (IOException ioe) {
    // Problem writing data
    System.out.println("Banner SaveImage - IOException");
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);

    rs.closeRecordStore();
    rs = null;

    return false;
    }
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);
    rs.closeRecordStore();
    rs = null;


    System.out.println("Banner SaveImage - OK");
    return true; // We've successfuly done
    }

    //Delete stored image based on campaignId
    private void DeleteStoredImage (String imageCid) throws RecordStoreException {

    if (RecordStore.listRecordStores() != null) {
    RecordStore.deleteRecordStore(imageCid);
    }

    }

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Cannot Delete RecordStore although RecordStore is closed already

    Quote Originally Posted by playplay1978 View Post
    Hi... my class has 2 methods which 1 of them saves image to RecordStore and the other one loads the saved image from RecordStore. In some conditions, some of the saved images need to be deleted from the RecordStore.
    Well, i keep getting "javax.microedition.rms.RecordStoreException: deleteRecordStore error: record store is still open". I'm pretty sure i have closed the RecordStore but it just can't be deleted.
    Below is the excerpt of my code. Since my original code is very long, i just enter the 3 relevant methods. Please kindly help.

    //A function to load image from the memory
    public Image LoadImage(int width, int height, String imageCid) throws RecordStoreException {
    rs = RecordStore.openRecordStore(imageCid, true);

    byte[] b = null;
    String imagename = null;
    Image image = null;

    if (rs.getNumRecords() > 0) {

    try {

    int i = rs.getNumRecords();

    for(int j = 1; j < i + 1; j++) {

    if(rs.getRecord(j) != null) {

    b = rs.getRecord(j);
    ByteArrayInputStream bin =
    new ByteArrayInputStream( b );

    DataInputStream din = new DataInputStream( bin );

    imageCid = din.readUTF();
    int remaining =
    (b.length-imageCid.getBytes().length-2)/4;

    int[] rawdata = new int[remaining];

    for(int k =0 ;k<rawdata.length ;k++) {
    rawdata[k] = din.readInt();
    }

    image = Image.createRGBImage(rawdata,
    width, height, false);

    bin.reset();
    din.close();
    din =null;
    }
    }
    } catch (IOException e) {

    e.printStackTrace();

    } catch(RecordStoreException recordstoreexception) {

    recordstoreexception.printStackTrace();

    }
    finally {
    System.out.println("Banner LoadImage - closing RecordStore of " + imageCid);
    rs.closeRecordStore();
    rs = null;


    }
    }
    return image;
    }

    //A function to save image to the memory of the device
    public boolean SaveImage (Image img, int width,
    int height, String imageCid) throws RecordStoreException {
    rs = RecordStore.openRecordStore(imageCid, true);

    if (img == null || width < 0 || height < 0 || imageCid == null) {

    throw new IllegalArgumentException("Check arguments");

    }

    int[] imgRgbData = new int[width * height];

    try {

    img.getRGB(imgRgbData, 0, width, 0, 0, width, height);

    } catch (Exception e) {
    // Problem getting image RGB data
    return false;
    }
    try {
    // Write image data to output stream (in order to get
    // the record bytes in needed form)
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeUTF(imageCid);

    for (int i = 0; i < imgRgbData.length; i++) {
    dos.writeInt(imgRgbData[i]);
    }

    // Open record store, create if it doesn't exist
    rs.addRecord(baos.toByteArray(), 0,
    baos.toByteArray().length); // Add record

    } catch (RecordStoreNotFoundException rsnfe) {
    // Record storage not found
    System.out.println("Banner SaveImage - RecordStoreNotFound");
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);

    rs.closeRecordStore();
    rs = null;

    return false;
    } catch (RecordStoreException rse) {
    // Other record storage problem
    System.out.println("Banner SaveImage - RecordStoreNotException");
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);

    rs.closeRecordStore();
    rs = null;

    return false;
    } catch (IOException ioe) {
    // Problem writing data
    System.out.println("Banner SaveImage - IOException");
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);

    rs.closeRecordStore();
    rs = null;

    return false;
    }
    System.out.println("Banner SaveImage - closing RecordStore of " + imageCid);
    rs.closeRecordStore();
    rs = null;


    System.out.println("Banner SaveImage - OK");
    return true; // We've successfuly done
    }

    //Delete stored image based on campaignId
    private void DeleteStoredImage (String imageCid) throws RecordStoreException {

    if (RecordStore.listRecordStores() != null) {
    RecordStore.deleteRecordStore(imageCid);
    }

    }
    Where exactly you are calling the DeleteStoredImage(imageCid) method.
    Please check before calling this method you need to ensure that the respected RecordStore should be closed.

    Thanks & Regards,
    Ajit

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Cannot Delete RecordStore although RecordStore is closed already

    Hello,

    Well you are not managing the opening and closing the record store properly, that's why you are getting the exception.Somewhere you are missing to close the RMS.Do one thing take int variable and increase this while you open the RMS and decrease the same when you are closing the RMS.Do paint the variable value on the console or canvas.It is hard to see the long code and find the instant error in the same.First you do the finding on your own and try to fix the same.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    27

    Re: Cannot Delete RecordStore although RecordStore is closed already

    Hi. In my code, i called DeleteStoredImage from the following method. This image also calls LoadImage and SaveImage which i wrote here in the 1st post.
    FYI, GetImage is called by the instance of my class periodically. Based on number of call times and some other conditions, i need to clear some of the images and etc.

    Thanks again.

    public Image GetImage () throws IOException {
    int w, h;
    Image image = null;

    if (callTimes > 9999) {
    callTimes = 0;
    }

    if (index > (adsParam.length - 1)) {
    index = 0;
    }

    if (imgW[index] == 0) {
    w = imageWidth;
    }
    else {
    w = imgW[index];
    }
    if (imgH[index] == 0) {
    h = imageHeight;
    }
    else {
    h = imgH[index];
    }
    try {
    image = LoadImage(w, h, String.valueOf(campaignId));
    if (image == null) {
    image = GetImageFromUrl(imageUrl + "?partnerid=" + partnerId + "&cid=" + campaignId + "&imgsize=" + imageSize);
    imgW[index] = image.getWidth();
    imgH[index] = image.getHeight();
    if (SaveImage(image, imgW[index], imgH[index], String.valueOf(campaignId)) == true) {
    System.out.println("Banner - GetImage - SaveImage " + campaignId);
    }
    }

    }
    catch (RecordStoreException rsE) {rsE.printStackTrace();}
    exposures[index]++;
    if ((callTimes % 10) == 0 && (callTimes != 0)) {
    try {
    for (int i = 0; i < adsParam.length; i++) {
    AddExposures(cntr, exposures[i], clientId, Integer.parseInt(adsParam[i][1]));
    exposures[i] = 0;
    }
    //Refresh the list every 20 calls
    if ((callTimes % 20) == 0) {
    for (int i = 0; i < adsParam.length; i++) {
    if ((imgH[i] != imageHeight) && (imgW[i] != imageWidth)) {
    //Delete RecordStore for this image
    try {
    DeleteStoredImage(adsParam[i][1]);
    System.out.println("Banner GetImage - Delete Stored Image for " + adsParam[i][1]);
    }
    catch (RecordStoreException rsE) {
    rsE.printStackTrace();
    }
    }
    }

    adsParam = getAdsParam(getAdsUrl + "?partnerid=" + partnerId + "&clientid=" + clientId);
    }

    }
    catch (IOException io) {
    io.printStackTrace();
    }
    }
    index++;
    callTimes++;
    return image;
    }

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Cannot Delete RecordStore although RecordStore is closed already

    Quote Originally Posted by playplay1978 View Post
    Hi. In my code, i called DeleteStoredImage from the following method. This image also calls LoadImage and SaveImage which i wrote here in the 1st post.
    FYI, GetImage is called by the instance of my class periodically. Based on number of call times and some other conditions, i need to clear some of the images and etc.

    Thanks again.

    public Image GetImage () throws IOException {
    int w, h;
    Image image = null;

    if (callTimes > 9999) {
    callTimes = 0;
    }

    if (index > (adsParam.length - 1)) {
    index = 0;
    }

    if (imgW[index] == 0) {
    w = imageWidth;
    }
    else {
    w = imgW[index];
    }
    if (imgH[index] == 0) {
    h = imageHeight;
    }
    else {
    h = imgH[index];
    }
    try {
    image = LoadImage(w, h, String.valueOf(campaignId));
    if (image == null) {
    image = GetImageFromUrl(imageUrl + "?partnerid=" + partnerId + "&cid=" + campaignId + "&imgsize=" + imageSize);
    imgW[index] = image.getWidth();
    imgH[index] = image.getHeight();
    if (SaveImage(image, imgW[index], imgH[index], String.valueOf(campaignId)) == true) {
    System.out.println("Banner - GetImage - SaveImage " + campaignId);
    }
    }

    }
    catch (RecordStoreException rsE) {rsE.printStackTrace();}
    exposures[index]++;
    if ((callTimes % 10) == 0 && (callTimes != 0)) {
    try {
    for (int i = 0; i < adsParam.length; i++) {
    AddExposures(cntr, exposures[i], clientId, Integer.parseInt(adsParam[i][1]));
    exposures[i] = 0;
    }
    //Refresh the list every 20 calls
    if ((callTimes % 20) == 0) {
    for (int i = 0; i < adsParam.length; i++) {
    if ((imgH[i] != imageHeight) && (imgW[i] != imageWidth)) {
    //Delete RecordStore for this image
    try {
    DeleteStoredImage(adsParam[i][1]);
    System.out.println("Banner GetImage - Delete Stored Image for " + adsParam[i][1]);
    }
    catch (RecordStoreException rsE) {
    rsE.printStackTrace();
    }
    }
    }

    adsParam = getAdsParam(getAdsUrl + "?partnerid=" + partnerId + "&clientid=" + clientId);
    }

    }
    catch (IOException io) {
    io.printStackTrace();
    }
    }
    index++;
    callTimes++;
    return image;
    }
    DeleteStoredImage(adsParam[i][1]);
    System.out.println("Banner GetImage - Delete Stored Image for " + adsParam[i][1]);

    Just swap the above two statement in your application and see wheather adsParam[i][1] giving the actuat name of recordStore or not.

    Thanks & Regards,
    Ajit

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    27

    Re: Cannot Delete RecordStore although RecordStore is closed already

    Yes. it gives the actual name(s) of the RecordStore(s).

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    27

    Smile Re: Cannot Delete RecordStore although RecordStore is closed already

    Thanks all especially to raj_J2ME.

    With raj_J2ME's suggestion, i have found the cause and solved this issue.

    I made an mistake in LoadImage. The closing of RecordStore is only performed inside
    if (rs.getNumRecords() > 0) {
    ...
    }

    After i added
    rs.CloseRecordStore();
    rs = null

    it works already.

Similar Threads

  1. Delete Record from RecordStore
    By mobileben in forum Mobile Java General
    Replies: 6
    Last Post: 2012-07-27, 08:27
  2. Client exit when new sms(general sms, not related with APP) comes,
    By sanjeevmehtaubi in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2009-04-22, 16:06
  3. delete RecordStore problem
    By decisor in forum Mobile Java General
    Replies: 5
    Last Post: 2006-08-04, 22:26
  4. Cannot delete RecordStore in Nokia emulator
    By pdm9 in forum Mobile Java General
    Replies: 1
    Last Post: 2003-08-14, 15:33
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×