Hi
I am testing to write a contact list program. I store the information regarding name, Organization name, tel no and e-mail. When I select the read command, it shows all the organization name, e-mail in the list. It is all ok so far.
I want to write the program as when I choose one contact [organization name, e-mail] in the list, I want to show the detail info [name, organization name, email, tel no].
But now the program is showing java.lang.NoClassDefFoundError: ListCommandHandler error message.
What is the problem?
import java.util.Enumeration;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.pim.*;
public class ZSecondContactMIDlet extends MIDlet implements CommandListener{
Form mainForm;
StringItem stItem;
Display display;
Command cmdExit;
Command cmdRead;
Command cmdDelete;
Command cmdWrite;
public ZSecondContactMIDlet() {
mainForm=new Form("Contact Program");
stItem=new StringItem("*******","Data has been entered");
cmdExit=new Command("Exit",Command.EXIT,0);
cmdRead=new Command("Read",Command.SCREEN,0);
cmdDelete=new Command("Delete",Command.SCREEN,0);
cmdWrite=new Command("Write",Command.SCREEN,0);
mainForm.append(stItem);
mainForm.addCommand(cmdRead);
mainForm.addCommand(cmdExit);
mainForm.addCommand(cmdDelete);
mainForm.addCommand(cmdWrite);
mainForm.setCommandListener(this);
display=Display.getDisplay(this);
Verify();
}
private void Verify() {
String version=System.getProperty("microedition.pim.version");
if(version==null)
{
System.out.println("PIM is not available");
}
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
display.setCurrent(mainForm);
}
public void commandAction(Command c, Displayable d) {
if(c==cmdExit)
{
try {
destroyApp(true);
notifyDestroyed();
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(c==cmdWrite)
{
PIM pim=PIM.getInstance();
ContactList contactlist=null;
Contact contact=null;
try {
contactlist=(ContactList)pim.openPIMList(PIM.CONTACT_LIST,PIM.WRITE_ONLY);
contact=contactlist.createContact();
String[]name_struct=new String[contactlist.stringArraySize(Contact.NAME)];
name_struct[Contact.NAME_GIVEN]="Rose";
name_struct[Contact.NAME_FAMILY]="Angel";
contact.addString(Contact.ORG, PIMItem.ATTR_NONE, "Microsoft");
contact.addString(Contact.TEL, PIMItem.ATTR_NONE, "099045464");
contact.addString(Contact.EMAIL, PIMItem.ATTR_NONE, "rose@gmail.com");
contact.commit();
} catch (PIMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(contactlist!=null)
{
try {
contactlist.close();
contactlist=null;
} catch (PIMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}//if(c==cmdWrite)
if(c==cmdRead)
{
List listName;
listName=new List("Name List",List.IMPLICIT);
listName.setCommandListener(new ListCommandHandler());
try {
PIM pim=PIM.getInstance();
ContactList contactlist=null;
Enumeration contacts=null;
contactlist=(ContactList)pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
Contact temp_contact=null;///////////////////
temp_contact=contactlist.createContact();//////////////////////
temp_contact.addString(Contact.ORG, PIMItem.ATTR_NONE, "M");/////////////
contacts=contactlist.items(temp_contact);
if(contacts==null)
{
System.out.println("There is no PIM record");
return;
}
while(contacts.hasMoreElements())
{
Contact contact=(Contact)contacts.nextElement();
String Orgname=contact.getString(Contact.ORG, 0);
String email=contact.getString(Contact.EMAIL,0);
listName.append(Orgname+","+email, null);
}
} catch (PIMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
display=Display.getDisplay(this);
display.setCurrent(listName);
}//if(c==cmdRead)
if(c==cmdDelete)
{
PIM pim=PIM.getInstance();
try {
ContactList contactlist=(ContactList)pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
Enumeration contact_temp=contactlist.items();
if(contact_temp==null)
{
System.out.println("there is no record to delete");
return;
}
while(contact_temp.hasMoreElements())
{
contactlist.removeContact((Contact)contact_temp.nextElement());
}//while
} catch (PIMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//if(c==cmdDelete)
}
}