【问题标题】:BlackBerry Persistent Store Throws java.lang.ErrorBlackBerry Persistent Store 引发 java.lang.Error
【发布时间】:2011-10-26 04:59:29
【问题描述】:

我正在尝试开发一个使用 appinfo 类来存储设置的应用程序。这是可以持久的。当我使用新安装的应用程序时,它运行良好。然后,如果我重新加载 cod,任何持久性存储访问尝试都会抛出 java.lang.error 并声称我没有权限(在进入应用程序内部之前暂停应用程序权限异常)。

要让我的应用再次运行,我必须清理模拟器并重新启动它。

编辑:忘了提一下,只要我设法打开它,并在应用程序当前在模拟器中打开时重新加载代码,它就可以继续工作。

Edit2:它开始看起来像 6.0 问题。因为如果我在 7.0 模拟器中打开它,一切都很好。

应用信息:

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;
    }
}

持久存储助手:

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( appInfoStore );
    }



    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;
    }
}

将 app info 变量放入我使用它的类中。

public static AppInfo AppData;
    static{
        AppData = PersistentStoreHelper.retrieveAppInfo();
        if (AppData == null){
            AppData = new AppInfo();
            PersistentStoreHelper.saveAppInfo(AppData);
        }
    }

在“main”函数中创建应用程序后我的程序的第一行。

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

任何帮助将不胜感激。这是模拟器问题还是我的问题?

【问题讨论】:

    标签: blackberry store persistent


    【解决方案1】:

    这是一个模拟器错误。在其他设备上调试持久存储时,它工作正常。它的火炬 6.0.0.246 等有问题。在“热交换”鳕鱼文件后,它没有正确删除以前的持久存储。安装到普通设备时,如果您要更新应用程序,然后选择“稍后重新启动”,然后尝试打开该应用程序,就会出现这种错误。

    开发模拟器错误。

    【讨论】:

      猜你喜欢
      • 2012-10-08
      • 1970-01-01
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多