bluelagoon88
asked on
J2ME RMS(Record Management System)
hi, wanna ask if someone could code out a sample code whereby it can store names and phone numbers into the RMS. Thank you.
ASKER
petmagdy, can this code be modified so that it can be use to store only the names and numbers in a handphone? Currently doin a project that needs to store people's names and contacts into the handphone(RMS). Thanks in advance.
ASKER
by the way.. i need to compile it as a MIDlet
Using Wireless toolkit to compile. Thanks again.
Using Wireless toolkit to compile. Thanks again.
You can store any thing u want it is not structured u are just as if u r storing rows, each row is a byte[], so u construct a string by cocatinating a name + '|' + handphone number, i am using '|' character as a separator u can choose something else, to construct ur MIDP application and compile and assemble ur application as JAD and JAR easily I recommend for u Sun Java studio Mobility 6 u can download it from
http://wwws.sun.com/software/download/products/41085de1.html
good luck
http://wwws.sun.com/software/download/products/41085de1.html
good luck
ASKER
petmagdy, theres an error in the coding.. may i know what is the problem?
C:\WTK20\apps\MMStore\src\ MMStore.ja va:19: cannot resolve symbol
symbol : variable m_bOpened
location: class MMStore
if(!m_bOpened)
^
1 error
com.sun.kvem.ktools.Execut ionExcepti on
Build failed
C:\WTK20\apps\MMStore\src\
symbol : variable m_bOpened
location: class MMStore
if(!m_bOpened)
^
1 error
com.sun.kvem.ktools.Execut
Build failed
yes put under the line
protected RecordStore m_TopScores;
this line to define m_bOpened
protected boolean m_bOpened;
protected RecordStore m_TopScores;
this line to define m_bOpened
protected boolean m_bOpened;
ASKER
ok thanks.. i will see wat i can do..
ASKER
theres an error in this set of code... wats the problem with it?
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --
import javax.microedition.rms.*;
import javax.microedition.midlet. *;
import javax.microedition.lcdui.* ;
import java.io.*;
public class RecordStoreExample
extends MIDlet implements CommandListener
{
private Display display;
private Alert alert;
private Form form;
private Command exit;
private Command start;
private RecordStore recordstore = null;
private RecordEnumeration recordenumeration = null;
public RecordStoreExample ()
{
display = Display.getDisplay(this);
exit = new Command("Exit", Command.SCREEN, 1);
start = new Command("Start", Command.SCREEN, 1);
form = new Form("Record Store");
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(th is);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destoryApp (boolean unconditional)
{
}
public void commandAction(Command command, Displayable displayable)
{
if (Command == exit)
{
destoryApp(true);
notifyDestoryed();
}
else if (command == start)
{
try
{
recordstore = RecordStore.openRecordStor e("myRecor dStore", true);
}
catch (Exception error)
{
alert = new Alert("Error Creating", error.toString(), null, AlertType.Warning);
alert.setTimeout(Alert.FOR EVER);
display.setCurrent(alert);
}
if (RecordStore.listRecordSto res() != null)
{
try
{
RecordStore.deleteRecordSt ore("myRec ordStore") ;
}
catch (Exception error)
{
alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
alert.setTimeout(Alert.FOR EVER);
display.setCurrent(alert);
}
}
}
}
}
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- --------
Here's the error message:
c:\WTK104\apps\RecordStore Example\sr c\RecordSt oreExample .java:5: RecordStoreExample is not abstract and does not override abstract method destroyApp(boolean) in javax.microedition.midlet. MIDlet
public class RecordStoreExample
^
c:\WTK104\apps\RecordStore Example\sr c\RecordSt oreExample .java:37: cannot resolve symbol
symbol : variable Command
location: class RecordStoreExample
if (Command == exit)
^
c:\WTK104\apps\RecordStore Example\sr c\RecordSt oreExample .java:40: cannot resolve symbol
symbol : method notifyDestoryed ()
location: class RecordStoreExample
notifyDestoryed();
^
c:\WTK104\apps\RecordStore Example\sr c\RecordSt oreExample .java:50: cannot resolve symbol
symbol : variable Warning
location: class javax.microedition.lcdui.A lertType
alert = new Alert("Error Creating", error.toString(), null, AlertType.Warning);
^
4 errors
--------------------------
import javax.microedition.rms.*;
import javax.microedition.midlet.
import javax.microedition.lcdui.*
import java.io.*;
public class RecordStoreExample
extends MIDlet implements CommandListener
{
private Display display;
private Alert alert;
private Form form;
private Command exit;
private Command start;
private RecordStore recordstore = null;
private RecordEnumeration recordenumeration = null;
public RecordStoreExample ()
{
display = Display.getDisplay(this);
exit = new Command("Exit", Command.SCREEN, 1);
start = new Command("Start", Command.SCREEN, 1);
form = new Form("Record Store");
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(th
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destoryApp (boolean unconditional)
{
}
public void commandAction(Command command, Displayable displayable)
{
if (Command == exit)
{
destoryApp(true);
notifyDestoryed();
}
else if (command == start)
{
try
{
recordstore = RecordStore.openRecordStor
}
catch (Exception error)
{
alert = new Alert("Error Creating", error.toString(), null, AlertType.Warning);
alert.setTimeout(Alert.FOR
display.setCurrent(alert);
}
if (RecordStore.listRecordSto
{
try
{
RecordStore.deleteRecordSt
}
catch (Exception error)
{
alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
alert.setTimeout(Alert.FOR
display.setCurrent(alert);
}
}
}
}
}
--------------------------
Here's the error message:
c:\WTK104\apps\RecordStore
public class RecordStoreExample
^
c:\WTK104\apps\RecordStore
symbol : variable Command
location: class RecordStoreExample
if (Command == exit)
^
c:\WTK104\apps\RecordStore
symbol : method notifyDestoryed ()
location: class RecordStoreExample
notifyDestoryed();
^
c:\WTK104\apps\RecordStore
symbol : variable Warning
location: class javax.microedition.lcdui.A
alert = new Alert("Error Creating", error.toString(), null, AlertType.Warning);
^
4 errors
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also in the line
if (Command == exit)
change it to:
if (command == exit)
if (Command == exit)
change it to:
if (command == exit)
sorry also u wrote this line wrongly:
notifyDestoryed();
write it:
notifyDestroyed();
Also change
alert = new Alert("Error Creating", error.toString(), null, AlertType.Warning);
to
alert = new Alert("Error Creating", error.toString(), null, AlertType.WARNING);
again be case sensitive
notifyDestoryed();
write it:
notifyDestroyed();
Also change
alert = new Alert("Error Creating", error.toString(), null, AlertType.Warning);
to
alert = new Alert("Error Creating", error.toString(), null, AlertType.WARNING);
again be case sensitive
ASKER
ok thx... i'll try it out
import javax.microedition.rms.*;
import java.io.*;
import java.util.*;
public class MMStore
{
//Single Tone Class
protected RecordStore m_TopScores;
/** Creates a new instance of MMStore */
public MMStore() throws Exception
{
m_TopScores = RecordStore.openRecordStor
}
public void close() throws Exception
{
if(!m_bOpened)
{
return;
}
m_TopScores.closeRecordSto
}
protected static byte[] constructRecord(Vector elements, char cSeparator)
{
String szRecord="";
int nSize= elements.size();
for(int i=0; i < nSize ; i++)
{
szRecord += (String) elements.elementAt(i);
if( i < (nSize - 1))
{
String sep = String.valueOf(cSeparator)
szRecord += sep;
}
}
//System.out.println("Cons
return szRecord.getBytes();
}
public int getTopScoresRecordsCount()
{
return m_TopScores.getNumRecords(
}
public Integer addTopScore(String szName, int nTrials) throws Exception
{
Vector elements = new Vector();
int nLevel=2;
elements.addElement(szName
elements.addElement(String
elements.addElement(String
byte[] record = constructRecord(elements,'
int nRecID=m_TopScores.addReco
return new Integer(nRecID);
}
public void removeAllScores() throws Exception
{
Hashtable topScores = new Hashtable();
//System.out.println("Star
RecordEnumeration enum = m_TopScores.enumerateRecor
//System.out.println("enum
if(enum == null)
{
return;
}
while(enum.hasNextElement(
{
int nRecId=enum.nextRecordId()
m_TopScores.deleteRecord(n
}
}
}