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)	
		
		
	}

}

Hi,
I am a beginner in j2me programming. Whenever I encounter an error message, it is difficult for me to find the place where the mistake exists. I do not get any hint from the error message. For example, in this message, what is the meaning of bci=0? What does bci stands for?
I am sorry if this is a stupid question.
java.lang.NoClassDefFoundError: ListCommandHandler
- java.lang.Class.invoke_verify(), bci=0
- java.lang.Class.initialize(), bci=117
- java.lang.Class.forName(), bci=0
- com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=1
- com.sun.midp.midlet.MIDletStateHandler.createMIDlet(), bci=66
- com.sun.midp.midlet.MIDletStateHandler.createAndRegisterMIDlet(), bci=17
- com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=27
- com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52
- com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8
- com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161
- com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26

Not sure myself what bci stands for (and don't believe that you need to know), but, considering that the error is coming from sun.com.midp I have a few ideas.

One, are you instantiating an instance of a com.sun class yourself? If so the warning here.

Two, did you maxbe use Java 6 to compile something for Java 5 without using all the necessary options to javac for that (or some other similar version bridging compilation)? If that even might be so see this (scroll down to the "Cross-Compilation Example" and then up to the options description to get a more thorough explanation).

Three, does ListCommandHandler (and possibly even the sun class, and this class may also be part of the sun package, I guess) come from a third-party lib, and if so, is it on the classpath (seemingly not, if so)? It is not part of the Java 6 API, anyway.

As you can see I have merged your threads. Please do not start multiple threads on the same topic.

Now I see that you are using JME, and not directly instatiating a sun.* class. Points 2 and 3 still apply, however, just you need to look at the JME documentation.

That is as far as I can go know, I don't do anything with JME, myself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.