hi all,
I have a problem in getting the retreived values from the record store and place it in an array.
The code is as follows:
public void append(String charText)
{
if(item>1)
this.items.append(charText+"*");
else
this.items.append(charText);
}
public void openRecStore()
{
try
{
// The second parameter indicates that the record store
// should be created if it does not exist
rs = RecordStore.openRecordStore("All Items", true );
}
catch (Exception e)
{
System.out.println("Exception in opening: "+e.getMessage());
}
}
public void closeRecStore()
{
try
{
rs.closeRecordStore();
}
catch (Exception e)
{
System.out.println("Exception in closing record: "+e.getMessage());
}
}
/*--------------------------------------------------
* Create array of data to write into record store
*-------------------------------------------------*/
public void writeTestData()
{
String[] items = {
"bag101-Laptop Bag-Rs.600",
"bag102-Travel Bag-Rs.500",
"bag103-School Bag-Rs.350",
"wal201-Leather Wallet-Rs.400",
"wal202-Trifold Wallet-Rs.450",
"wal203-Double Slimfold Wallet-Rs.300",
"sht501-Formal Shirts-Rs.1500",
"sht502-Casual Shirts-Rs.1050",
"sht503-Kids Shirts-Rs.700"};
writeRecords(items);
}
private void writeRecords(String[] items) {
byte[] record;
try
{
// Only add the records once
if (rs.getNumRecords() > 0)
return;
for (int i = 0; i < items.length; i++)
{
record = items[i].getBytes();
rs.addRecord(record, 0, record.length);
}
}
catch (Exception e)
{
System.out.println("Exception in writing records: "+e.getMessage());
}
}
/*--------------------------------------------------
* Search using enumerator and record filter
*-------------------------------------------------*/
public void searchRecordStore()
{
int i =0;
try
{
System.out.println("Number of records: "+rs.getNumRecords());
// Record store is not empty
if (rs.getNumRecords() > 0)
{
// Setup the search filter with the user requested text
SearchFilter search = new SearchFilter(msc.code);
RecordEnumeration re = rs.enumerateRecords(search, null, false);
// A match was found using the filter
if (re.numRecords() > 0)
{
while (re.hasNextElement()) {
int id = re.nextRecordId();
System.out.println("Record ID: " + id);
String str2 = null;
str2 = new String(rs.getRecord(id));
item++;
append(str2);------->i have a problem here, i am unable to place in an array
//System.out.println("Values which start with" + str2);//+" are "+str1[i]);
//searchResult+=str2;
//System.out.println("Search Results: "+searchResult);
}
}
re.destroy(); // Free enumerator
}
itemDetails=items.toString();
System.out.println("Items are: "+items.toString());
}
catch (Exception e)
{
System.out.println("Exception in searching for a record: "+e.getMessage());
}
}
/*--------------------------------------------------
* Search for text within a record
* Each record passed in contains only text (String)
*-------------------------------------------------*/
public class SearchFilter implements RecordFilter
{
private String searchText = null;
private String searchNoResult = null;
public SearchFilter(String searchText)
{
// This is the text to search for
this.searchText = searchText.toLowerCase();
}
public boolean matches(byte[] candidate)
{
String str = new String(candidate).toLowerCase();
// Look for a match
if (searchText != null && str.startsWith(searchText))
return true;
else
searchNoResult="No Item Found";
return false;
}
}
Please help me out

Reply With Quote




