如何比较blackberry中的persistentObject值

时间:2010-06-24 14:40:43

标签: java blackberry

我正在开发一个用于eclipse的jdp插件中的黑莓应用程序。我想在黑莓设备的闪存中存储一​​些数据库,并且&还要检查数据值是否已经存在于内存中。我正在给出我试图用持久对象做的代码,但是有些我能够得到我想要的东西,plz修改代码所在的地方

package com.firstBooks.series7.db;

import java.util.Random;
import com.firstBooks.series7.AppMain;
import com.firstBooks.series7.db.parser.XMLParser;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;

public class DBMain {
  public static String answer = "";
  public static String selectedAnswer = "";
  public static Question curQuestion;

  public static int currQuesNumber = 1;
  public static int correctAnswerCount = 0;
  public static int totalNumofQuestions = 50 ;

  static int quesNum[] = new int[20];
  static int quesNumNew[];
  static int quesCount = -1;

  static int randomPosition;
  static PersistentObject store;
  static {
    store = PersistentStore.getPersistentObject( 0xf9f8c7a20bc35c51L);
  }

  static{   
    initialize();   
  }

  private static void initialize(){

    Random rgen = new Random();  // Random number generator

    //--- Initialize the array 
    for (int i=0; i<quesNum.length; i++) {
      quesNum[i] = i;
    }

    //--- Shuffle by exchanging each element randomly
    for (int i=0; i< quesNum.length; i++) {
      randomPosition = rgen.nextInt(quesNum.length);

      int temp = quesNum[i];

      quesNum[i] = quesNum[randomPosition];

      quesNum[randomPosition] = temp;

      synchronized(store) {
        if(quesNum[randomPosition]!=quesNum[i]){
          System.out.println("...........i can do it............ ");
          store.setContents(quesNum);
          store.commit();
        }
      }
    }
  }

  /*Changed the code to get a unique random number
   * @author: Venu   
   */
  public static int getQuestionNumber() {
    quesCount++;
    if(quesCount < quesNum.length){
      synchronized(store) {
        int [] quesNumNew = (int[])store.getContents();

        return quesNumNew[quesCount];
      }
    }
    else{ 
      initialize();
      quesCount = -1;
      return getQuestionNumber();
    }
  }
}

1 个答案:

答案 0 :(得分:0)

您遇到的问题是什么?您是否尝试将数组包装在实现Persistable接口的对象中?它就像j2se中的Serializable接口。

另见: http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/util/Persistable.html

  

“类必须显式实现此接口,以便系统持久存储类的实例。”