package com.firstBooks.series.db;
import java.util.Random;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import java.util.Vector;
import net.rim.device.api.util.Arrays;
import net.rim.device.api.util.Persistable;
import com.firstBooks.series.db.parser.XMLParser;
import com.firstBooks.series.ui.managers.TopManager;
import com.firstBooks.series.ui.screens.TestScreen;
public class DBMain implements Persistable{
public static String answer = "";
public static String selectedAnswer = "";
public static Question curQuestion;
public static int currQuesNumber = 1;
public static int correctAnswerCount = -1;
static int curQuesnew;
static int quesCount=-1;
static int xyz;
static int j=0;
public static int totalNumofQuestions = Question.totques;
public static int quesNum[] = new int[XMLParser.questionList.size()];
static PersistentObject qStore;
static PersistentObject curQues;
static PersistentObject pQues;
static PersistentObject curans;
static PersistentObject disques;
static int a ;
static int b;
static int pques;
static int cans;
static int []dques;
static Vector data = new Vector();
static {
qStore = PersistentStore.getPersistentObject(0x33010065d24c7883L);
curQues = PersistentStore.getPersistentObject(0x33010064d24c7883L);
pQues = PersistentStore.getPersistentObject(0xbd7460a5b4f9890aL);
curans = PersistentStore.getPersistentObject(0xc5c065a3ae1bec21L);
disques = PersistentStore.getPersistentObject(0x9e6d76868a999451L);
}
static{
initialize();
}
public static void initialize() {
//int quesNum[] = new int[XMLParser.questionList.size()];
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++) {
int randomPosition = rgen.nextInt(quesNum.length);
int temp = quesNum[i];
quesNum[i] = quesNum[randomPosition];
quesNum[randomPosition] = temp;
}
synchronized (qStore) {
qStore.setContents(quesNum);
qStore.commit();
}
}
public static int getQuestionNumber() {
quesCount++;
synchronized (curans) {
int b=Integer.parseInt(TopManager.corrCount);
curans.setContents(b+"");
curans.commit();
}
int quesNum[];
synchronized (qStore) {
quesNum=(int[]) qStore.getContents();
System.out.println("The value of question is ...."+quesNum.length);
}
synchronized (pQues) {
int a=Integer.parseInt(TopManager.quesNumber);
pQues.setContents(a+"");
pQues.commit();
}
if (quesNum!=null && quesCount < quesNum.length) {
data.addElement(TestScreen.quesNumber+"");
synchronized (curQues) {
curQuesnew=quesNum[quesCount];
curQues.setContents(curQuesnew+"");
curQues.commit();
}
synchronized (disques) {
data = (Vector)disques.getContents();
System.out.println("valueee is.........."+data.size());
}
synchronized (disques) {
if (data == null) {
System.out.println("value is "+data);
disques.setContents(data);
disques.commit();
}
}
if (data.contains(quesNum[quesCount]+"")){
initialize();
System.out.println("i shall overcome.........");
getQuestionNumber();
}
else {
System.out.println("hardwork conqures all.........");
xyz=quesNum[quesCount];
}
return quesNum[quesCount];
} else {
initialize();
quesCount = -1;
return getQuestionNumber();
}
}
When i am trying to call getContents() first,& then store it using setContents,my application is nt running,& if i dnt use new vector() at top,then my values are not being saved into the vector,so for that i need to declare new vetor() at top,but when i save the values into persistent store & exit the app,then again restart my app,the vector start frm a new value.I want the vector to hold the previous 10 values,& start frm 11th value,plz help.