2011-08-12 35 views
1

我正在嘗試開發一個應用程序,該應用程序使用appinfo類來存儲設置。這是持久的。當我使用新安裝的應用程序時,它完美地工作。然後,如果我重新加載cods,任何持久性存儲訪問嘗試都會拋出java.lang.error並聲明我沒有權限(甚至在輸入應用程序的內容之前暫停應用程序權限異常)。BlackBerry持久存儲引發java.lang.Error

爲了讓我的應用程序再次工作,我必須清理模擬器並重新啓動它。

編輯:忘了提及,只要我已經設法打開它,並在應用程序當前在模擬器中打開時重新加載鱈魚,它就會繼續工作。

編輯2:它開始看起來像一個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); 
     } 
    } 

的第一線我在「主」功能中創建應用程序後的程序。

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等有問題。在「熱切換」鱈魚文件後,它沒有正確刪除以前的持久性存儲。當安裝到常規設備時,如果您要更新應用程序,並選擇「稍後重新啓動」,然後嘗試打開該應用程序,則會出現此錯誤。

開發模擬器錯誤。