Bonjour, J'ai essaye de creer un fichier XML qui prend une simple listeView setté avec un adapter perso comme ceci:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <ListView
            android:id="@+id/listpromo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
voici mon activité:

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
public class ListSample_category3 extends Activity 
    {
 
    	public final static String ITEM_TITLE = "title";
    	public final static String ITEM_COMPANY= "company";
    	public final static String ITEM_DATE = "availabledate";
    	private ListView list;
 
    	public Map<String,?> createItem(String title, String company, String date) 
    	{
    		Map<String,String> item = new HashMap<String,String>();
    		item.put(ITEM_TITLE, title);
    		item.put(ITEM_COMPANY, company);
    		item.put(ITEM_DATE, date);
    		return item;
    	}
 
    	@Override
    	public void onCreate(Bundle bundle) 
    	{
    		super.onCreate(bundle);
 
    		List<Map<String,?>> security = new LinkedList<Map<String,?>>();
    		security.add(createItem("Remember passwords", "Cisco", "2012-02-10"));
    		security.add(createItem("Clear passwords", "Microsoft", "2012-02-10"));
    		security.add(createItem("Show security warnings", "Apple", "2012-02-10"));
 
    		// create our list and custom adapter
    		SeparatedListAdapter adapter = new SeparatedListAdapter(this);
 
    		adapter.addSection("Categorie 1", new ArrayAdapter<String>(this,
    			R.layout.list_item_category3, new String[] { "First item", "Item two" }));
 
    		adapter.addSection("Categorie 2", new SimpleAdapter(this, security, R.layout.list_complex_category3, 
    			new String[] { ITEM_TITLE, ITEM_COMPANY, ITEM_DATE }, new int[] { R.id.list_complex_title, R.id.list_complex_company, R.id.list_complex_date }));
 
    		// create ListView
    		//ListView list = new ListView(this);
    		list = (ListView) findViewById(R.id.listpromo);
 
    		// OnItemClickListener on all items
    		OnItemClickListener listener = new OnItemClickListener()
    	    {
    	    	  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    	    	  {
 
    	    	  }
    	    };
    		list.setOnItemClickListener(listener);
    	    list.setItemsCanFocus(true);
 
    	    list.setAdapter(adapter);
    		this.setContentView(list);
 
    	}
    }
Mais j'ai un NullPointerException :

08-05 14:49:24.875: E/AndroidRuntime(2558): FATAL EXCEPTION: main
08-05 14:49:24.875: E/AndroidRuntime(2558): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dev.prixo/com.dev.prixo.OngletsActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dev.prixo/com.dev.prixo.ListSample_category3}: java.lang.NullPointerException
08-05 14:49:24.875: E/AndroidRuntime(2558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-05 14:49:24.875: E/AndroidRuntime(2558): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-05 14:49:24.875: E/AndroidRuntime(2558): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-05 14:49:24.875: E/AndroidRuntime(2558): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-05 14:49:24.875: E/AndroidRuntime(2558): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 14:49:24.875: E/AndroidRuntime(2558): at android.os.Looper.loop(Looper.java:130)
08-05 14:49:24.875: E/AndroidRuntime(2558): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dev.prixo/com.dev.prixo.ListSample_category3}: java.lang.NullPointerException

Je ne vois pas d'ou viens le pb..