Bonjour,

Je ne parviens pas à afficher des informations extraites de ma BDD dans une liste.

Voici le fichier (cursor_row.xml) contenant des ListView :

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
 
<?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" >
 
 
    <TextView
    android:id="@+id/id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="50" /> 
 
    <TextView
    android:id="@+id/intitule"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="50" />
 
    <TextView
    android:id="@+id/salaire"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="50" />
 
</LinearLayout>
Et 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
57
58
59
60
61
62
63
64
65
66
67
68
 
import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;
 
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
	  @Override
	  public void onCreate(Bundle savedInstanceState) {
 
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.cursor_row);
 
	    //ecrire dans la table
	    MetierDAO MetierDAOS = new MetierDAO(this);
	    MetierDAOS.open();
	    Metier Metier = new Metier(1,"intitule",2);
	    MetierDAOS.ajouter(Metier);    
 
	    Cursor cursor = MetierDAOS.mDb.rawQuery("SELECT id as _id, intitule, salaire FROM metier WHERE intitule = ?", new String[]{"intitule"});
	    cursor.moveToFirst();
	    //TextView textView = new TextView(this); 
	    //String nbligne = String.valueOf(cursor.getCount());
	    //textView.setText(nbligne);    
            //setContentView(textView);
            //Me renvoi bien le nombre de ligne ds ma table metier
 
       Cadapter = new SimpleCursorAdapter (this, R.layout.cursor_row, cursor, new String[]{MetierDAO.INTITULE, MetierDAO.SALAIRE}, new int[]{R.id.intitule, R.id.salaire});
 
    	ListView listView1 = (ListView) findViewById(R.id.salaire);
    	listView1.setAdapter(adapter);
        //long id = cursor.getLong(0);
	   // String intitule = cursor.getString(1);
	    //double salaire = cursor.getDouble(2);
       	long id;
   		String intitule;
   		double salaire;
 
        while (cursor.moveToNext()) {
        	id = cursor.getLong(0);
        	intitule = cursor.getString(1);
        	salaire = cursor.getDouble(2);
        	Metier m = new Metier(id, intitule, id);
        	TextView textView2 = new TextView(this);
    	    textView2.setText(m.getIntitule());    
            setContentView(textView2);
	    }
        	View v = getLayoutInflater().inflate(R.layout.cursor_row, null);
 	    	ListView listView1 = (ListView) v.findViewById(R.id.intitule);
	    	listView1.setAdapter(adapter);
 
	        cursor.close();
 
	    MetierDAOS.close();
 
	  };
 
}
Mon LogCat me donne ce message d'erreur (Uniquement quand j'utilise findViewById):
07-07 20:16:25.190: E/AndroidRuntime(23191): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.resto/com.android.resto.MainActivity}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 113.

Merci d'avance...