Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-05-2009, 08:41 AM
Member
 
Join Date: Apr 2009
Posts: 12
Rep Power: 0
JavaJunkie is on a distinguished road
Default Store data is not retrieving
Hi,

I'm stuck in the problem of retrieving the stored data in midlet. Whenever I try to retrieve the data I'm getting the following exception:
Code:
java.lang.ArrayIndexOutOfBoundsException
	at javax.microedition.rms.RecordStore.getRecordIDs(+61)
	at javax.microedition.rms.RecordEnumerationImpl.rebuild(+21)
	at javax.microedition.rms.RecordEnumerationImpl.<init>(+41)
	at javax.microedition.rms.RecordStore.enumerateRecords(+15)
	at recordStore.dis1(+34)
	at Project.commandAction(+313)
	at javax.microedition.lcdui.List.callKeyPressed(+80)
	at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(+198)
	at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(+11)
	at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(+127)
	at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(+210)
	at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+114)
	at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
The code which I've used in storing the data is:

Code:
ByteArrayOutputStream stream=new ByteArrayOutputStream();
DataOutputStream writer=new DataOutputStream(stream);
  writer.writeUTF(t.getString());// t and t1 here is a reference of TextField type
  writer.writeUTF(t1.getString());
  

    byte[] b=stream.toByteArray();
                      
	byte[] b1=stream.toByteArray();
	  rs.addRecord(b,0,b.length);
	  rs.addRecord(b1,0,b1.length);

and the code which I've used for retrieving the stored data is:

ByteArrayInputStream stream;
DataInputStream reader;


Code:
RecordEnumeration en=rs.enumerateRecords(null,null,false);
 int id=en.nextRecordId();


 while(en.hasNextElement())
 {

byte[] rec=new byte[rs.getRecordSize(id)];
rec=rs.getRecord(id);
stream=new ByteArrayInputStream(rec);
reader=new DataInputStream(stream);
System.out.println(reader.readUTF());

Thanks in advance.

Last edited by JavaJunkie; 05-05-2009 at 09:04 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-05-2009, 10:26 PM
Member
 
Join Date: Apr 2009
Posts: 12
Rep Power: 0
JavaJunkie is on a distinguished road
Default
Please reply. I'm still having trouble in solving this problem.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-30-2009, 09:08 AM
Member
 
Join Date: Mar 2009
Posts: 2
Rep Power: 0
gopicsq is on a distinguished road
Default RecordStore
table="login"

openRecStore();

if (ns == 0) {
writeRecord("dileepp");
writeRecord("1207sp");
writeRecord("000002");
writeRecord("True");
writeRecord("True");

}

public void openRecStore(){
try{ rs = RecordStore.openRecordStore(table,true );
}catch (Exception e){}
}



public void writeRecord(String str){
byte[] rec = str.getBytes();
try{rs.addRecord(rec, 0, rec.length);
}catch (Exception e){}
}




public void readRecords(){


int ln=0;
mdes = new String[ln];

String[] sArry;
try{
ln = rs.getNumRecords();
}catch (Exception e){}

mdes = new String[ln];

int x=0;
try{
byte[] recData = new byte[rs.getNumRecords()];
int len;
for(int i = 1; i <= rs.getNumRecords(); i++){
recData = new byte[rs.getRecordSize(i)];
len = rs.getRecord(i, recData, 0);
String des = new String(recData, 0, len);
mdes[i] = des ;

}




} // for loop



}catch (Exception e){}


if ( ln == 0) {
Alert error = new Alert ("Status","No Record found in "+table+ " Table",null, AlertType.INFO );
error.setTimeout(Alert.FOREVER);
}



}



Regards

Gopinath
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help me to store data in a class neeraj.singh New To Java 2 08-06-2009 09:31 AM
how to store the data in data base eclipse3.4ide New To Java 5 02-03-2009 05:25 AM
what's the fastest method of storing and retrieving large amounts of data in Java? 2potatocakes New To Java 1 12-28-2008 11:25 AM
error while retrieving data from data base kirtesh4u New To Java 5 11-15-2008 05:10 PM
Retrieving data from the DB yuchuang Database 2 11-27-2007 09:59 AM


All times are GMT +2. The time now is 06:38 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org