infkb
Messages postés46Date d'inscriptionmercredi 10 août 2005StatutMembreDernière intervention18 janvier 2011
-
10 sept. 2005 à 21:44
infkb
Messages postés46Date d'inscriptionmercredi 10 août 2005StatutMembreDernière intervention18 janvier 2011
-
14 sept. 2005 à 12:25
Salut,
j'ai commencer une petite application avec j2me , dont je fais entrer 4 champs texte a savoir le nom, le prenom,le fixe et l'adresse d'un contact.
par une methode appeler ajouter. Je sauvegarde et j'affiche avec une methode affiche().mais le probleme c'est que j'ai rien qui s'enregistre, et il y a des erreurs lors de l'affichage.
Veuillez me repondre c'est trés urgent, merci d'avance.
voila le code:
public Test() {
display = Display.getDisplay(this);
form = new Form("Annuaire Menu");
txt_nom = new TextField("Name", "", 32, 0);
txt_prenom = new TextField("Prenom","", 32,0);
txt_fixe = new TextField("Fixe","", 32,0);
txt_adresse = new TextField("Adresse","", 32,0);
forma = new Form("Ajout");
formm = new Form("Modifier");
forms = new Form("Supprimer");
formc = new Form("Choix Type Contact");
AjoutCommand = new Command("Ajout", Command.SCREEN, 1);
ModifieCommand = new Command("Moudifier", Command.SCREEN, 1);
ChercheCommand = new Command("Chercher", Command.SCREEN, 1);
DeleteCommand = new Command("effacer", Command.SCREEN, 1);
EditCommand = new Command("Afficher", Command.SCREEN, 1);
form.addCommand(AjoutCommand);
form.addCommand(ModifieCommand);
form.addCommand(ChercheCommand);
form.addCommand(EditCommand);
form.addCommand(DeleteCommand);
form.setCommandListener(this);
sortir=new Command("sortir",Command.EXIT,1);
save=new Command("save",Command.SCREEN,2);
form.addCommand(sortir);
}
public void startApp() {
init();
}
public void pauseApp() {
}
public void commandAction(Command c, Displayable d){
if (c.getCommandType() == Command.EXIT){
notifyDestroyed();
}
if (c AjoutCommand || c List.SELECT_COMMAND) {
ajout();
}
else if (c ModifieCommand || c List.SELECT_COMMAND) {
display.setCurrent(formm);
}
else if (c ChercheCommand || c List.SELECT_COMMAND) {
display.setCurrent(formc);
}
else if (c EditCommand || c List.SELECT_COMMAND) {
affiche();
}
else if (c DeleteCommand || c List.SELECT_COMMAND) {
display.setCurrent(forms);
}
else if (c == save)
{
save();
init();
}
}
public void init(){
try{
// la liste des contacts
// On ouvre le RecordStore "Contact"
RecordStore rs_Contact = RecordStore.openRecordStore("Contact",true);
RecordEnumeration re_Contact = rs_Contact.enumerateRecords(null,null,true);
//On instancie deux tableaux (un contenant l'id et l autre le nom)
tab_Contact = new String[re_Contact.numRecords()+1];
tab_id = new String[re_Contact.numRecords()+1];
tab_Contact[0] = "Nouveau";
tab_id[0] = "0";
for(int j = 1 ; re_Contact.hasNextElement();j++)
{
int id = re_Contact.nextRecordId();
tab_Contact[j] = getInfo(id)[0];
tab_id[j] = ""+id;
}
//On ferme le RecordStore
rs_Contact.closeRecordStore();
}
catch(Exception e){}
liste_contact = new ChoiceGroup("Choisissez un Contact:", Choice.EXCLUSIVE,tab_Contact, null);
form.append(liste_contact);
int i = liste_contact.getSelectedIndex();
display.setCurrent(form);
}
public void save()
{
try
{
//On ouvre une connexion au RecordStore
RecordStore rs_Contact = RecordStore.openRecordStore("Contact",true);
String nom = txt_nom.getString();
String prenom = txt_prenom.getString();
String fixe = txt_fixe.getString();
String adresse = txt_adresse.getString();
//On compose le string finale de l'enregistrement
String finale = nom+"<sep>"+prenom+"<sep>"+fixe+"<sep>"+adresse;
byte[] byte_finale = finale.getBytes();
rs_Contact.addRecord(byte_finale,0,byte_finale.length);
//On ferme le recordstore
rs_Contact.closeRecordStore();
}
catch(Exception e){}
}
//ajout
public void ajout()
{
try
{
//On ouvre une connexion au RecordStore
RecordStore rs_Contact = RecordStore.openRecordStore("Contact",true);
forma.append(txt_nom);
forma.append(txt_prenom);
forma.append(txt_fixe);
forma.append(txt_adresse);
forma.addCommand(sortir);
forma.addCommand(save);
forma.setCommandListener(this);
display.setCurrent(forma);
//On ferme le recordstore
rs_Contact.closeRecordStore();
}
catch(Exception e){}
forma.addCommand(AjoutCommand);
forma.addCommand(ModifieCommand);
forma.addCommand(ChercheCommand);
forma.addCommand(EditCommand);
forma.addCommand(DeleteCommand);
display.setCurrent(forma);
}
public void destroyApp(boolean unconditional) {
}
//getInfo(int) permet de decouper un enregistrement a l'aide de son ID
public String[] getInfo(int id)
{
try
{
//On ouvre le RecordStore
RecordStore rs_Contact = RecordStore.openRecordStore("Contact",true);
//On recupere l enregistrement
String temp = new String(rs_Contact.getRecord(id));
//On instancie un tableau de string
String[] resultat = new String[4];
//On decoupe l'enregistrement entre chaque | et l on place chaque partie
//dans chaque case du tableau
int i=0;
while (i<3) {
resultat[i] = temp.substring(0,temp.indexOf("<sep>"));
temp = temp.substring(temp.indexOf("<sep>")+4);
i++;
}
resultat[3] = temp;
//On ferme le RecordStore
rs_Contact.closeRecordStore();
return resultat;
}
catch(Exception e)
{
String[] erreur = {"erreur","erreur","erreur","erreur"};
return erreur;
}
}
public void affiche()
{
forme = new Form("editer");
//On instancie 4 TextField
txt_nom = new TextField("", "", 20,0);
txt_prenom = new TextField("", "", 20,0);
txt_fixe = new TextField("", "", 20,0);
txt_adresse= new TextField("", "", 20,0);
//On recupere l'id
int selected_id = Integer.parseInt(tab_id[liste_contact.getSelectedIndex()]);
String[] info = getInfo(selected_id);
txt_nom.setString(info[0]);
txt_prenom.setString(info[1]);
txt_fixe.setString(info[2]);
txt_adresse.setString(info[3]);
//On ajoute les elements a la form
forme.append("Nom : ");
forme.append(txt_nom);
forme.append("Prenom : ");
forme.append(txt_prenom);
forme.append("Fixe : ");
forme.append(txt_fixe);
forme.append("Adresse : ");
forme.append(txt_adresse);
forme.setCommandListener(this);
display.setCurrent(forme);
}
}
infkb
Messages postés46Date d'inscriptionmercredi 10 août 2005StatutMembreDernière intervention18 janvier 2011 12 sept. 2005 à 13:29
Bonjour,
Merci d'abord de m'avoir répondu,pour l'erreur c'est ç le problème car a la compilation j'ai pas d'erreur mais lors de l'execution j'appelle la methode ajout() pour ajouter des contact puis j'enregistre avec la methode save(),or lors de l'appelle de la methode affiche() pour afficher les contact ajouter j'ai dans les champs Textfields nom,prenom.... erreur.
Je ne sais pas est ce que la methode getInfo() pour l'extraction des données est incorrecte ou qoui? j'ai uiliser Tokenizer mais il ne marche pas pour j2me peut etre car je travaille avec cldc1 midp1 dont voila le code:
public static String[] getInfo(String finale){
String[] resultat = new String[5];
StringTokenizer st = new StringTokenizer(finale,"'|'");
try{
int i=0;
while ((st.hasMoreTokens()) &&(i<=4)) {
resultat[i] = st.nextToken();
i++;
}
return resultat;
} catch(Exception e)
{
String[] erreur = {"erreur","erreur","erreur","erreur","erreur"};
return erreur;}
}
Veuillez svp me répondre car c'est urgent pour moi c'est juste un test mais j'ai un projet basé sur cela que je dois le presenter dans peu de jours .
Merci encore une fois pour votre aide.
infkb
Messages postés46Date d'inscriptionmercredi 10 août 2005StatutMembreDernière intervention18 janvier 2011 13 sept. 2005 à 15:29
Salut,
j'ai cru que mon problème est du à l'utilisation J2ME Wireless Toolkit.1.0.4_02, c'est pour cela j'ai installer J2ME Wireless Toolkit 2.2
la compilation ç passe Build complete, mais lors de l'execution j'ai ce message d'erreur:
Running with storage root DefaultColorPhone
Cannot connect socket to port 1551
Windows error code 10061
Cannot open socket for LIME events on port 1551
Je ne sais pas est ce que c'est du à ORACLE 8i (seveur) et que le programme que j'execute ne utilise pas de socket.
infkb
Messages postés46Date d'inscriptionmercredi 10 août 2005StatutMembreDernière intervention18 janvier 2011 14 sept. 2005 à 12:25
Salut,
Pour J2ME Wireless Toolkit 2.2, j'ai pu l'installer dans une autre partition autre que celle au ORACLE8i est installer. est ç a marcher, mais le probleme que j'avais que le resultat que mon programme doit afficher ne marche toujours pas.
merci.