Yop à tous,

Voila j'ai un souci, j'ai codé un application de test qui devrait en principe retrouvé un contact par sont nom.

L'ennui c'est que le programme plante à cette ligne :

if(cContact.getString(Contact.NAME,0).compareTo("Sandrine") == 0){

Aucun message d'erreur , rien, l'application plante complètement. Comment dois-je récupérer le nom d'un contact ?

J'ai esseye comme ceci aussi, mais même plantage :
if(cContact.getString(Contact.NAME,Conctact.NAME).compareTo("Sandrine") == 0){

Voici le code complèt de l'application, il est tout petit


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.*;
// PIM APIs
import javax.microedition.pim.*;
 
// Generated class. Modify.
public final class MyCLdcl extends MIDlet implements CommandListener {
    private final Command exitCommand;
    private final Form mainForm;
    private PIM pimHinst;
    private ContactList clMyContact;
 
    public MyCLdcl() {
	// Constructor. Place your code here.   
        mainForm = new Form("MyConctactListTest");
        exitCommand = new Command("Exit", Command.EXIT, 1);
        mainForm.addCommand(exitCommand);
        mainForm.setCommandListener(this);
        Display.getDisplay(this).setCurrent(mainForm);
    }
 
    protected void startApp() {
	String szPimVersion;        
	// Testing if the PIM APIs are supported.
	if((szPimVersion = System.getProperty("microedition.pim.version")) == null){
		mainForm.append("Your mobile do not support the PIM APIs");
	}else{
		pimHinst = PIM.getInstance();
 
		try{
			clMyContact = (ContactList) pimHinst.openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);
 
			java.util.Enumeration enumContacts = clMyContact.items();
			Contact cContact;
			boolean boFinded = false;
			while(enumContacts.hasMoreElements()) {
				cContact = (Contact) enumContacts.nextElement();
				if(cContact.getString(Contact.NAME,0).compareTo("Sandrine") == 0){
					boFinded = true;				
				}
			}
			if(!boFinded){
				mainForm.append("Not Finded");
			}else{
				mainForm.append("Finded");;
			}
 
		}catch (PIMException pe) {
			mainForm.append("No such list");
			for(int i=0;i<5000000;i++);
		} catch (SecurityException se) {
			mainForm.append("MIDlet is not allowed access to the specified list");
			for(int i=0;i<5000000;i++);
		}
 
	}
    }
 
    protected void pauseApp() {
        // Place your code here.
    }
 
    protected void destroyApp(boolean unconditional) {
        // Place your code here.
    }
 
    public void commandAction(Command c, Displayable d) {
        // Place your code here.
        if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}
Merci d'avance. cela me serait d'une très grande aide.