Bonjour,

Pour commencer je tiens à m'excuser si ce topic n'est pas à sa place mais je suis nouveau sur ce site et ne connais pas l'ensemble de son arborescence.

Je dois effectuer un projet sous Android pour mon école où je dois gérer une base de donnée.

Lorsque je crée ma table "randonnees", je lui demande de nommer ma clé primaire "_id" (après recherche j'ai vu qu'on était obligé de la nommer ainsi), mais lorsque je compile mon code le Logcat m'affiche un message d'erreur comme quoi il n'existe pas de colonne "_id".
Ci-joint mon code + le Logcat.

Main.java

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
package com.test;
 
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
 
public class Main extends ListActivity{
    /** Called when the activity is first created. */
 
	DBAdapter db;
	Randonnee[] rando = new Randonnee[14];
 
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initialiserLesRandonnees();
        db = new DBAdapter(this);
        db.open();
        db.Truncate();
        initialiserLaListe();
        DataBind();
    }
 
	public void DataBind(){
		Cursor cursor = db.recupererLaListeDesRandonnees();
		startManagingCursor(cursor);
    	SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.randonnee_layout,
    			cursor, new String[]{"nom","ville","genre"},
    			new int[]{R.id.TV_Nom,R.id.TV_Ville,R.id.TV_Genre});
    	Log.i("", "ok3");
    	setListAdapter(adapter);
    }
 
	public void onListItemClick(ListView l, View v, int position, long id){
		Cursor cursor = (Cursor)l.getAdapter().getItem(position);
		Intent intent = new Intent(this,Main2.class);
		intent.putExtra("madonnee", cursor.getString(cursor.getColumnIndex("_id")));
		this.startActivityForResult(intent, 1000);
	}
 
	protected void onDestroy(){
    	db.close();
    	super.onDestroy();
    }
 
	public void initialiserLaListe(){
		int i;
		for(i=0;i<14;i++)
			db.insererUneRandonnee(rando[i]);
	}
 
	public void initialiserLesRandonnees() {
		rando[0] = new Randonnee("Nom1", "Ville1", "En montagne", 43.74563, 6.0947);
		rando[1] = new Randonnee("Nom2", "Ville2", "A la mer", 43.4398, 8.0475);
		rando[2] = new Randonnee("Nom3", "Ville3", "A la mer", 43.0984, 9.1034);
		rando[3] = new Randonnee("Nom4", "Ville4", "En montagne", 43.7564, 5.8437);
		rando[4] = new Randonnee("Nom5", "Ville5", "En montagne", 43.7564, 6.7463);
		rando[5] = new Randonnee("Nom6", "Ville6", "A la mer", 43.64537, 7.74389);
		rando[6] = new Randonnee("Nom7", "Ville7", "En montagne", 43.9843, 5.8437);
		rando[7] = new Randonnee("Nom8", "Ville8", "A la mer", 43.64367, 6.74379);
		rando[8] = new Randonnee("Nom9", "Ville9", "A la mer", 43.84387, 6.8783);
		rando[9] = new Randonnee("Nom10", "Ville10", "En montagne", 43.64536, 7.64736);
		rando[10] = new Randonnee("Nom11", "Ville11", "A la mer", 43.54637, 4.73748);
		rando[11] = new Randonnee("Nom12", "Ville12", "A la mer", 43.657383, 6.637);
		rando[12] = new Randonnee("Nom13", "Ville13", "En montagne", 43.74838, 7.8738);
		rando[13] = new Randonnee("Nom14", "Ville14", "A la mer", 43.74738, 6.64378);
	}
}
Main2.java

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
 
package com.test;
 
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
 
public class Main2 extends ListActivity {
 
	TextView text;
	DBAdapter db;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main2);
 
		text=((TextView)this.findViewById(R.id.TextView01));
		if(this.getIntent().getExtras()!=null){
        	String s = this.getIntent().getExtras().getString("madonnee");
        	Cursor cursor = db.recupererUneRandonnee(s);
        	startManagingCursor(cursor);
        	SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
        	R.layout.randonnee_layout,cursor,new String[]{"nom","ville","genre"},
        	new int[]{R.id.TV_Nom,R.id.TV_Ville,R.id.TV_Genre});
        	setListAdapter(adapter);
        }
	}
}
Randonnee.java

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
 
package com.test;
 
import com.google.android.maps.GeoPoint;
 
public class Randonnee{
	public String nom;
	public String ville;
	public String genre;
	public GeoPoint coords;
 
	public Randonnee(String aNom, String aVille, String aGenre, double aLatitude, double aLongitude){
		int latitude, longitude;
		nom = aNom;
		ville = aVille;
		genre = aGenre;
		latitude = convert(aLatitude);
		longitude = convert(aLongitude);
		coords = new GeoPoint(latitude, longitude);
	}
 
	public int convert(double nombre) {
		return (int)(nombre*1000000);
	}
}
DBAdapter.java

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
80
81
82
83
84
85
86
87
88
 
package com.test;
 
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
 
public class DBAdapter{
	DatabaseHelper DBHelper;
	Context context;
	SQLiteDatabase db;
 
	public DBAdapter(Context context){
		this.context = context;
		DBHelper = new DatabaseHelper(context);
	}	
 
	public class DatabaseHelper extends SQLiteOpenHelper{
		Context context;
 
		public DatabaseHelper(Context context){
			super(context, "randonnees", null, 1);
			this.context = context;
		}
 
		@Override
		public void onCreate(SQLiteDatabase db){
			db.execSQL("create table randonnees(" +
					"_id integer primary key autoincrement," +
					"nom text not null, ville text not null," +
					"genre text not null," +
					"latitude decimal(8,6)," +
					"longitude decimal(8,6));");			
		}
 
		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
			Toast.makeText(context, "Mise à jour de la Base de données version "+oldVersion+" vers "+newVersion, Toast.LENGTH_SHORT).show();
			db.execSQL("DROP TABLE IF EXISTS randonnees");
			onCreate(db);
		}	
	}
 
	public DBAdapter open(){
		db = DBHelper.getWritableDatabase();
		return this;
	}
 
	public void close(){
		db.close();
	}
 
	public void Truncate(){
		db.execSQL("DELETE FROM randonnees");
	}
 
	public long insererUneRandonnee(Randonnee rando){
		ContentValues values = new ContentValues();
		values.put("nom", rando.nom);
		values.put("ville", rando.ville);
		values.put("genre", rando.genre);
		values.put("latitude", rando.coords.getLatitudeE6()/1000000);
		values.put("longitude", rando.coords.getLongitudeE6()/1000000);
		return db.insert("randonnees", null, values);
	}
 
 
	public boolean supprimerRandonnee(long id){
		return db.delete("randonnees", "_id="+id, null)>0;
	}
 
	public Cursor recupererLaListeDesRandonnees(){
		return db.query("randonnees", new String[]{
				"nom",
				"ville",
				"genre"}, null, null, null, null, null);
	}
 
	public Cursor recupererUneRandonnee(String id){
		return db.query("randonnees", new String[]{
				"nom",
				"ville",
				"genre"}, "_id = " + id, null, null, null, null);
	}
}
le logcat


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
80
81
82
83
84
85
86
87
88
89
90
91
92
03-02 15:12:27.780: DEBUG/AndroidRuntime(13648): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-02 15:12:27.780: DEBUG/AndroidRuntime(13648): CheckJNI is ON
03-02 15:12:28.010: DEBUG/AndroidRuntime(13648): --- registering native functions ---
03-02 15:12:28.020: INFO/jdwp(13648): received file descriptor 20 from ADB
03-02 15:12:28.740: DEBUG/PackageParser(563): Scanning package: /data/app/vmdl11194.tmp
03-02 15:12:28.870: INFO/PackageManager(563): Removing non-system package:com.test
03-02 15:12:28.880: DEBUG/PackageManager(563): Removing package com.test
03-02 15:12:28.880: DEBUG/PackageManager(563):   Activities: com.test.Main com.test.Main2
03-02 15:12:29.040: DEBUG/dalvikvm(563): GC freed 15628 objects / 851664 bytes in 128ms
03-02 15:12:29.160: DEBUG/PackageManager(563): Scanning package com.test
03-02 15:12:29.170: INFO/PackageManager(563): /data/app/vmdl11194.tmp changed; unpacking
03-02 15:12:29.185: DEBUG/installd(543): DexInv: --- BEGIN '/data/app/vmdl11194.tmp' ---
03-02 15:12:29.490: DEBUG/dalvikvm(13654): DexOpt: load 34ms, verify 104ms, opt 1ms
03-02 15:12:29.513: DEBUG/installd(543): DexInv: --- END '/data/app/vmdl11194.tmp' (success) ---
03-02 15:12:29.520: DEBUG/PackageManager(563):   Activities: com.test.Main com.test.Main2
03-02 15:12:29.620: INFO/installd(543): move /data/dalvik-cache/data@app@vmdl11194.tmp@classes.dex -> /data/dalvik-cache/data@app@com.test.apk@classes.dex
03-02 15:12:29.640: DEBUG/PackageManager(563): New package installed in /data/app/com.test.apk
03-02 15:12:29.750: DEBUG/AndroidRuntime(13648): Shutting down VM
03-02 15:12:29.760: DEBUG/dalvikvm(13648): DestroyJavaVM waiting for non-daemon threads to exit
03-02 15:12:29.770: DEBUG/dalvikvm(13648): DestroyJavaVM shutting VM down
03-02 15:12:29.770: DEBUG/dalvikvm(13648): HeapWorker thread shutting down
03-02 15:12:29.780: DEBUG/dalvikvm(13648): HeapWorker thread has shut down
03-02 15:12:29.780: DEBUG/jdwp(13648): JDWP shutting down net...
03-02 15:12:29.780: DEBUG/jdwp(13648): +++ peer disconnected
03-02 15:12:29.780: INFO/dalvikvm(13648): Debugger has detached; object registry had 1 entries
03-02 15:12:29.800: DEBUG/dalvikvm(13648): VM cleaning up
03-02 15:12:29.810: DEBUG/dalvikvm(13648): LinearAlloc 0x0 used 629572 of 4194304 (15%)
03-02 15:12:29.820: DEBUG/ActivityManager(563): Uninstalling process com.test
03-02 15:12:29.940: DEBUG/HomeLoaders(613): application intent received: android.intent.action.PACKAGE_REMOVED, replacing=true
03-02 15:12:29.940: DEBUG/HomeLoaders(613):   --> package:com.test
03-02 15:12:29.950: DEBUG/HomeLoaders(613): application intent received: android.intent.action.PACKAGE_ADDED, replacing=true
03-02 15:12:29.960: DEBUG/HomeLoaders(613):   --> package:com.test
03-02 15:12:29.960: DEBUG/HomeLoaders(613):   --> update package com.test
03-02 15:12:29.990: WARN/ResourceType(563): No package identifier when getting value for resource number 0x7f060001
03-02 15:12:30.250: DEBUG/dalvikvm(563): GC freed 3808 objects / 196784 bytes in 249ms
03-02 15:12:30.260: WARN/ResourceType(563): No package identifier when getting value for resource number 0x7f060000
03-02 15:12:30.270: WARN/ResourceType(563): No package identifier when getting value for resource number 0x7f060001
03-02 15:12:30.290: WARN/ResourceType(563): No package identifier when getting value for resource number 0x7f060000
03-02 15:12:30.630: DEBUG/AndroidRuntime(13659): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-02 15:12:30.640: DEBUG/AndroidRuntime(13659): CheckJNI is ON
03-02 15:12:30.850: DEBUG/AndroidRuntime(13659): --- registering native functions ---
03-02 15:12:30.860: INFO/jdwp(13659): received file descriptor 20 from ADB
03-02 15:12:32.090: INFO/ActivityManager(563): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.LAUNCHER} flags=0x10000000 comp={com.test/com.test.Main} }
03-02 15:12:32.180: INFO/ActivityManager(563): Start proc com.test for activity com.test/.Main: pid=13682 uid=10022 gids={}
03-02 15:12:32.200: DEBUG/AndroidRuntime(13659): Shutting down VM
03-02 15:12:32.200: DEBUG/dalvikvm(13659): DestroyJavaVM waiting for non-daemon threads to exit
03-02 15:12:32.210: DEBUG/dalvikvm(13659): DestroyJavaVM shutting VM down
03-02 15:12:32.220: DEBUG/dalvikvm(13659): HeapWorker thread shutting down
03-02 15:12:32.220: DEBUG/dalvikvm(13659): HeapWorker thread has shut down
03-02 15:12:32.243: DEBUG/jdwp(13659): JDWP shutting down net...
03-02 15:12:32.243: DEBUG/jdwp(13659): +++ peer disconnected
03-02 15:12:32.243: INFO/dalvikvm(13659): Debugger has detached; object registry had 1 entries
03-02 15:12:32.250: DEBUG/dalvikvm(13659): VM cleaning up
03-02 15:12:32.340: DEBUG/dalvikvm(13659): LinearAlloc 0x0 used 639228 of 4194304 (15%)
03-02 15:12:32.500: INFO/jdwp(13682): received file descriptor 20 from ADB
03-02 15:12:32.600: WARN/System.err(13682): Can't dispatch DDM chunk 46454154: no handler defined
03-02 15:12:32.600: WARN/System.err(13682): Can't dispatch DDM chunk 4d505251: no handler defined
03-02 15:12:33.680: DEBUG/AndroidRuntime(13682): Shutting down VM
03-02 15:12:33.680: WARN/dalvikvm(13682): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
03-02 15:12:33.690: ERROR/AndroidRuntime(13682): Uncaught handler: thread main exiting due to uncaught exception
03-02 15:12:33.700: ERROR/AndroidRuntime(13682): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.Main}: java.lang.IllegalArgumentException: column '_id' does not exist
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.os.Looper.loop(Looper.java:123)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.app.ActivityThread.main(ActivityThread.java:3948)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at java.lang.reflect.Method.invoke(Method.java:521)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at dalvik.system.NativeStart.main(Native Method)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.widget.CursorAdapter.init(CursorAdapter.java:111)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:47)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:85)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at com.test.Main.DataBind(Main.java:32)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at com.test.Main.onCreate(Main.java:26)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
03-02 15:12:33.700: ERROR/AndroidRuntime(13682):     ... 11 more
03-02 15:12:33.740: INFO/Process(563): Sending signal. PID: 13682 SIG: 3
03-02 15:12:33.751: INFO/dalvikvm(13682): threadid=7: reacting to signal 3
03-02 15:12:33.840: INFO/dalvikvm(13682): Wrote stack trace to '/data/anr/traces.txt'
03-02 15:12:42.121: WARN/ActivityManager(563): Launch timeout has expired, giving up wake lock!
03-02 15:12:42.731: WARN/ActivityManager(563): Activity idle timeout for HistoryRecord{43595410 {com.test/com.test.Main}}
03-02 15:12:47.590: INFO/Process(13682): Sending signal. PID: 13682 SIG: 9
03-02 15:12:47.600: INFO/ActivityManager(563): Process com.test (pid 13682) has died.
03-02 15:12:47.720: WARN/InputManagerService(563): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43610558
J'espère que ce sera assez clair pour que vous puissiez m'aider, merci d'avance,

Rerou