I write contact list that an inside of it has "add Contact" method which can add new contacts. My "contact list" application don't have an error but when I run it and try to use the "add Contact" method to add new contacts,it doesn't a new contact after I run the application again. Please tell me what is a solution of the problem.
This my "contact list" application.
and this class that have the "add contact" method"Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import javax.microedition.lcdui.*; import javax.microedition.io.*; /** * * @author Administrator */ public class contactlistmobile implements CommandListener { private Command Back,Ok; private ChoiceGroup contactselect; Display display; Displayable contactlistf; private Form contactMain; private int currentIndex; Displayable backscr; FriendList friendL; WorkplaceList workplaceL; RelationList relationL; public contactlistmobile(Display display,Displayable backmoni){ this.display= display; backscr = backmoni; // Create a multiple choice group contactselect = new ChoiceGroup("Contact Group", Choice.EXCLUSIVE); // Append options, with no associated images contactselect.append("Friend", null); contactselect.append("Workplace", null); contactselect.append("Relation", null); Ok = new Command("Ok", Command.OK, 1); Back = new Command("Back", Command.BACK,2); // Create Form, add components, listen for events contactMain = new Form(""); contactMain.append(contactselect); contactMain.addCommand(Ok); contactMain.addCommand(Back); contactMain.setCommandListener(this); contactlistf=contactMain; } public void commandAction(Command cmd, Displayable displayable){ if (cmd == Back) { display.setCurrent(backscr); } if(cmd == Ok) { currentIndex = contactselect.getSelectedIndex(); if(contactselect.getString(currentIndex) == "Friend"){ friendL = new FriendList(display,contactMain); friendL.LoadFriendContacts(); } if(contactselect.getString(currentIndex) == "Workplace"){ workplaceL = new WorkplaceList(display,contactMain); workplaceL.LoadWorkplaceContacts(); } if(contactselect.getString(currentIndex) == "Relation"){ relationL = new RelationList(display,contactMain); relationL.LoadRelationContacts(); } } } public void LoadContacts(){ display.setCurrent(contactlistf);} }
Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import javax.microedition.lcdui.*; import javax.microedition.io.*; /** * * @author Administrator */ public class FriendList implements CommandListener{ Displayable backcontact; private final Command okCommand, backCommand,addCommand,nextCommand; private Display dis; private TextBox Name,PhoneNumber; private ChoiceGroup friendselect; Form friendform; contactlistmobile contactlist; private String name,no; public FriendList(Display display,Displayable back){ this.dis = display; backcontact=back; friendselect= new ChoiceGroup("Friend",Choice.MULTIPLE); friendselect.append("Ham",null); friendselect.append("War",null); friendselect.append("George",null); friendselect.append("Kate",null); friendselect.append("",null); Name = new TextBox("Enter Name","",30,TextField.ANY); PhoneNumber = new TextBox("Enter Phone Number","",10,TextField.PHONENUMBER); okCommand = new Command("OK", Command.OK, 1); backCommand = new Command("Back", Command.BACK, 0); addCommand = new Command("Add",Command.OK,1); nextCommand= new Command("Next",Command.SCREEN,1); Name.addCommand(nextCommand); Name.setCommandListener(this); PhoneNumber.addCommand(addCommand); PhoneNumber.setCommandListener(this); friendform = new Form(""); friendform.append(friendselect); friendform.addCommand(backCommand); friendform.addCommand(okCommand); friendform.setCommandListener(this); } public void commandAction(Command cmd, Displayable displayable){ boolean select[] = new boolean[friendselect.size()]; int count=0; friendselect.getSelectedFlags(select); if(cmd == backCommand) { dis.setCurrent(backcontact); } if(cmd==okCommand) { for(int i=0;i<friendselect.size();i++){ if(select[i]==true) { count++; } } if(count>3) { } else if(select[4]==true) { dis.setCurrent(Name); } } if(cmd==addCommand) { name = Name.getString(); no = PhoneNumber.getString(); AddContacts(name); } if(cmd==nextCommand) { dis.setCurrent(PhoneNumber); } } public void LoadFriendContacts(){ dis.setCurrent(friendform); } public void AddContacts(String item) <--------"Add contact" method { friendselect.append(item,null); } }

Reply With Quote

