2011-08-12 8 views
1

設定を保存するためにappinfoクラスを使用するアプリケーションを開発しようとしています。これは持続可能です。新しくインストールしたアプリケーションを使用すると、完全に動作します。次に、コードをリロードすると、永続的なストアへのアクセス試行でjava.lang.errorがスローされ、私はパーミッションを持たないと主張します。BlackBerry Persistent Storeがスローされる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; 
    } 
} 

私はそれを使用するクラスにアプリ情報変数を取得

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 

任意の助けいただければ幸いです。これはシミュレータの問題ですか、これは私の問題ですか?

答えて

1

これはシミュレータのバグです。永続的なストアを他のデバイスでデバッグする場合、正常に動作します。そのトーチには問題がある6.0.0.246などがあります。 codファイルを "ホットスワップ"した後、以前の永続ストアを適切に削除しません。通常のデバイスにインストールするときに、アプリケーションを更新して「後で再起動する」を選択してから、アプリケーションを開こうとすると、これが発生します。

開発シミュレータエラー。