BlackBerry Persistent Store Throws java.lang.Error
I am attempting to develop an application that uses an appinfo class for storing settings. This is persistable. When I use the freshly installed application, it works perfectly. Then if I reload the cods, any persistant store access attempt will throw java.lang.error and claim I don't have permissions (suspends on application permission exception before even entering the guts of the application).
To get my app working again I have to clean the simulator and start it back up again.
Edit: Forgot to mention, as long as I have managed to get it open, and reload the cods while the app is currently open in the simulator, it continues to work.
Edit2: it is starting to look like a 6.0 issue. Since if I open it in the 7.0 simulator everything is peachy.
App Info:
package ca.dftr.lib.persistables;
import java.util.Hashtable;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.util.ContentProtectedHashtable;
import net.rim.device.api.util.Persistable;
/**
* Basic class for storing application specific information.
* Information such as application settings or whether the license agreement was accepted.
* For more complex and specific classes they should be implemented separately and implement persistable
* @author deforbes
*/
public class AppInfo extends ContentProtectedHashtable implements Persistable {
private String _appName = null;
private String _version = null;
/**
* Constructs the application info, creates and persists a hashtable for application settings.
* @param uniqueHexAppIdentifier Can be automatically created in resource class (BUNDLE_ID) or generated using other unique information.
*/
public AppInfo() {
ApplicationDescriptor appDesc = ApplicationDescriptor.currentApplicationDescriptor();
_appName = appDesc.getName();
_version = appDesc.getVersion();
}
/**
* Get the Name of the application
* @return The application name from the app descriptor
*/
public String getName()
{
return _appName;
}
/**
* Get the Version of the application
* @return The application version from the app descriptor
*/
public String getVersion()
{
return _version;
}
}
Persistent Store helper:
package ca.dftr.main;
import ca.dftr.lib.persistables.AppInfo;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
/**
* Persistant store helper class.
* Thanks to Max Gontar of Stack Overflow
* @author deforbes
*/
public class PersistentStoreHelper{
static PersistentObject appInfoStore = PersistentStore
.getPersistentObject( Global.GUID );
public static void saveAppInfo( AppInfo appInfo ){
saveObject( appInfoStore, appInfo );
}
public static AppInfo retrieveAppInfo(){
return ( AppInfo )retrieveObject( app开发者_运维问答InfoStore );
}
public static void saveObject( PersistentObject store, Object object ){
synchronized( store ){
store.setContents( object );
store.commit();
}
}
public static Object retrieveObject( PersistentObject store ){
Object result = null;
synchronized( store ){
result = store.getContents();
}
return result;
}
}
Getting the app info variable into the class I use it in.
public static AppInfo AppData;
static{
AppData = PersistentStoreHelper.retrieveAppInfo();
if (AppData == null){
AppData = new AppInfo();
PersistentStoreHelper.saveAppInfo(AppData);
}
}
The first lines of my program after creating the app within the "main" function.
Object acceptedLicense = Global.AppData.get("isLicenseAccepted");
if (acceptedLicense == null){
Global.AppData.put("isLicenseAccepted", new Boolean(false));
acceptedLicense = Global.AppData.get("isLicenseAccepted");
}
if (!((Boolean) acceptedLicense).booleanValue()){
//..... ETC. It crashes before this
Any help would be appreciated. Is this a simulator issue or is this my issue?
It is a simulator bug. When debugging persistent store on other devices it works fine. Its the torch 6.0.0.246 etc that have the problem. It does not properly remove the previous persistent store after "hot swapping" the cod files. When installing to a regular device, if you were to update an application, and select "restart later", and then try to open the app, this is the error you would get.
Development Simulator Error.
精彩评论