Bonjour,

J'ai lu beaucoup de tuto et de réponse a des questions sur différent site mais sans jamais réussir a faire quelque chose de fonctionnel.

Je voudrais faire une application qui envoi des sms et pour cela je voudrais récuperer la liste des contact.

Voici mon code :

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
findViewById(R.id.buttonContact).setOnClickListener(new Button.OnClickListener(){
        	public void onClick(View v){
        		String[] info = null;
        		int y=0;
        		Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
    			while (phones.moveToNext())
    			{
    				for (int i = 0; i < phones.getColumnCount(); i++) 
    	        	{
 
    	        			try
    	        			{
    	        				Log.i(phones.getColumnName(i) + "", phones.getString(i));
    	        			}
    	        			catch (Exception e) {
    	        				e.printStackTrace();
    						}
 
    	            }
 
    			  String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
    			  String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
    			  info[y] = phoneNumber;
					try
					{
						info[y] = phoneNumber;
					}
					catch (Exception e) {
						e.printStackTrace();
					}
    			  y++;
    			}
    			phones.close();
 
    			AlertDialog.Builder ad = new AlertDialog.Builder(getApplicationContext());
    			ad.setTitle("Contact");
 
    			ad.setItems(info, new DialogInterface.OnClickListener() {
 
					public void onClick(DialogInterface dialog, int which) {
						// Mettre le numéro dans une textarea
 
					}
				});
 
    			ad.show();
        	}
        });
Et voici mon erreur :

FATALEXCEPTION: main
java.lang.NullPointerException
at com.stuffco.trollsms.Third$2.onClick(Third.java:95)
etc ...

Voila si quelqu'un pouvait m'aider car je n'arrive vraiment a rien au niveau de l'accès des contact.

Cordialement