Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Record Management store issue

 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I tried executing the following code for maintaining a record store. The issue I am facing is that the first time when I run this code the record store is created and data is inserted in it.

package temp;


import javax.microedition.midlet.*;
import javax.microedition.rms.*;

public class recordstore extends MIDlet {

public recordstore() {
}
public void startApp() throws MIDletStateChangeException {
String s="";
RecordStore rs=null;
System.out.println(s);
try {

rs = RecordStore.openRecordStore("file6",true);
String temp="This is for phone number 5550001";
rs.addRecord(temp.getBytes(), 0,temp.getBytes().length);
System.out.println("record store file1 is opened and the record count is-->"+rs.getNumRecords());
}catch(Exception e){
System.out.println("Error: "+e.getMessage());
}
finally{
//close the record store
try {
rs.closeRecordStore();
System.out.println("record store file6 is closed");
}catch (Exception e){
System.out.println("Error: "+e.getMessage());
}
}
destroyApp(true);
notifyDestroyed();
}

/**
* Pause the MIDlet
*/
public void pauseApp() {
}

/**
* Called by the framework before the application is unloaded
*/
public void destroyApp(boolean unconditional) {
}
}


but the second time when I try using this code with the open record store set to false ( the record store should have been returned) I am getting a record store not found exception.

package temp;


import javax.microedition.midlet.*;
import javax.microedition.rms.*;

public class recordstore extends MIDlet {

public recordstore() {
}
public void startApp() throws MIDletStateChangeException {
String s="";
RecordStore rs=null;
System.out.println(s);
try {

rs = RecordStore.openRecordStore("file6",false);
String temp="This is for phone number 5550001";
rs.addRecord(temp.getBytes(), 0,temp.getBytes().length);
System.out.println("record store file1 is opened and the record count is-->"+rs.getNumRecords());
}catch(Exception e){
System.out.println("Error: "+e.getMessage());
}
finally{
//close the record store
try {
rs.closeRecordStore();
System.out.println("record store file6 is closed");
}catch (Exception e){
System.out.println("Error: "+e.getMessage());
}
}
destroyApp(true);
notifyDestroyed();
}

/**
* Pause the MIDlet
*/
public void pauseApp() {
}

/**
* Called by the framework before the application is unloaded
*/
public void destroyApp(boolean unconditional) {
}
}


Please help me out solve this issue.


Regards
Kartik
 
Darryl Burke
Bartender
Posts: 5149
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://forum.java.sun.com/thread.jspa?threadID=5301476
 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

You have redirected me to the Sun forum where I had asked the same question but did not get any reply. Could you please help me out with this issue.

Regards
M.Kartik
 
amal shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Tried your code..it didn't behave as you mentioned.

The only reason you can get that exception is while running the second time the "file6" might have been deleted.
 
Darryl Burke
Bartender
Posts: 5149
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by amal shah:
The only reason you can get that exception is while running the second time the "file6" might have been deleted.

Nope. It's because Kartik ran the two versions of his code simultaneously on two emulators.

Since that situation can't arise when running the code on a real device, there's nothing to worry about.
 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

Thanks for replying .
The reason i am trying to do this is :-

I need to showcase to my team as to how to communicate between two devices so I thought I will write a midlet and run it twice . On running the same midlet twice in wtk 2.5 I get 2 different emulators running . Now I can use the emulators to work as two seperate mobile phones.

The problem I am facing is :-
Since bot the emulators are running in the same jvm so I came across a case scenario whereby a single database recordstore is shared among all these midlet instances(same record store for all the emulators) but in reality when I create these midlet instances afresh they don't go for the existing record store but create a new record store.

Kindly help me solve these issues.

Regards
M.Kartik
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic