Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
nikhil_shravane2004
Posts: 109
Registered: ‎03-13-2010
My Device: BlackBerry 8520 Curve Smartphone

How to deal with RecordStoreException, not getting cause behind it.

[ Edited ]

Hi Everyone, I dont know where I have done wrong, but the following method is not working. I want to deleted all the recordStores at the beggining of the application, so I am calling the following application. All these record stores are created by the same application, just to inform you.

 

    public void deleteAllRecordStores(){
System.out.println("deleteAllRecordStores() method called");
if(RecordStore.listRecordStores() != null){
String[] recStoreNameList = RecordStore.listRecordStores();
for(int i=0; i<recStoreNameList.length; i++){
try {
System.out.println("Deleting RecordStore " + i + " " + recStoreNameList[i]);
RecordStore.deleteRecordStore(recStoreNameList[i]);
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
}
}
}

 

It is throwing RecordStoreException. Please can you tell me when this exception is thrown?

I am not getting the cause of exception. Is there any problem in the method? Please guide me.

Thanks and Best Regards.

 

Developer
nikhil_shravane2004
Posts: 109
Registered: ‎03-13-2010
My Device: BlackBerry 8520 Curve Smartphone

Re: How to deal with RecordStoreException, not getting cause behind it.

In the same way, at the start I am calling another method in which I am opening the record stores one by one, then check whether it contains the records or not. If it does not have any record, then I am deleting that particular record store. This method is working fine and deleting the selected record stores.

 

But the method which is not working [code is posted above], tries to delete all the record stores without any condition, and nothing else. So I am not getting what might be the problem. please guide me if you have any idea why this is happening.

 

Best Regards

Developer
Eugen
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE

Re: How to deal with RecordStoreException, not getting cause behind it.

Hi,

 

Here is what in javadoc:

If the record store is currently open by a MIDlet when this method is called, or if the named record store does not exist, a RecordStoreException will be thrown

 

Probably you RS is still opened in your application. Another possible error that other thread has already deleted this RS.

 

Thanks,

Eugen

 

Developer
nikhil_shravane2004
Posts: 109
Registered: ‎03-13-2010
My Device: BlackBerry 8520 Curve Smartphone

Re: How to deal with RecordStoreException, not getting cause behind it.

Thanks Eugen,

 

As I am calling above method just after starting the midlet, there is no chance of having any other thread deleting the record store. Also, As I am not opening any record store, there is no question of having RS opened. Still to make sure, I made some changes in the method as below:

 

 

public void deleteAllRecordStores(){
    System.out.println("deleteAllRecordStores() method called");
    if(RecordStore.listRecordStores() != null){
        String[] recStoreNameList = RecordStore.listRecordStores();
        RecordStore rs;
        for(int i=0; i<recStoreNameList.length; i++){
            try {
                rs = RecordStore.openRecordStore(recStoreNameList[i], true);
                rs.closeRecordStore();
                System.out.println("Deleting RecordStore " + i + " " + recStoreNameList[i]);
                RecordStore.deleteRecordStore(recStoreNameList[i]);
            } catch (RecordStoreException ex) {
                ex.printStackTrace();
            }
        }
    }
}

 

To make sure that the RS is not opened, I deliberately opened it and closed it. Still it is not working.

 

 

I think, it may be possible that midlets don't have permission to delete all the record stores on the device directly. So I tried one change in my midlet. While creating a record store, I provide the vendorName and suiteName. So that, when I will start midlet next time, it can be able to delete only its own record stores which were created in the first run. But during first run, while creating the record store it is returning null.

 

 

rs = RecordStore.openRecordStore(recStoreName, vendorName, suiteName);

i.e.. rs = null; so throwing null pointer exception.

 

Please can you tell me what is going wrong? Best Regards.