Bonjour,

Je travaille sur une application Android qui permet d'ajouter des produits dans une BDD SQLite.

Voilà ma fonction principale
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
package com.formation.sqlite;
 
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SimpleCursorAdapter;
 
public class SQLiteActivity extends ListActivity implements OnClickListener {
    DBAdapter db;
    Button btnAjout;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
 
        btnAjout = (Button) findViewById(android.R.id.button1);
        btnAjout.setOnClickListener(this);
 
        db = new DBAdapter(this);
        db.open();
 
        DataBind();
    }
 
    @Override
    protected void onDestroy()
    {
        db.close();
        super.onDestroy();
    }
 
    public void DataBind()
    {
        SimpleCursorAdapter adapter = null;
 
        Cursor c = db.recupererLaListeDesProduits();
 
        startManagingCursor(c);
 
        try{
        adapter = new SimpleCursorAdapter(this, R.layout.list_item, c, new String[]{"codeBarre","titre","description"}, new int[]{R.id.textCodeBarre,R.id.textTitre,R.id.textDescription});
        }
        catch(Exception e)
        {
            Log.i("TTT", e.getMessage());
        }
 
        setListAdapter(adapter);
    }
 
    @Override
    public void onClick(View arg0) {
 
        long num = SystemClock.currentThreadTimeMillis();
 
        db.insererUnProduit(""+num, "Produit n :"+num, "Nouveau produit + num");
        DataBind();
    }
}
Et voilà la classe DBAdapter :
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.formation.sqlite;
 
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, "produits", null, 1);
 
            this.context = context;
        }
 
        @Override
        public void onCreate(SQLiteDatabase db) {
 
            db.execSQL("CREATE TABLE produits (_id integer primary key autoincrement, codeBarre text not null, titre text not null, description text not null)");
        }
 
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
 
            Toast.makeText(context, "Mise à jour de la bdd version "+oldVersion+" vers "+newVersion, Toast.LENGTH_LONG).show();
            db.execSQL("DROP TABLE IF EXISTS produits");
            onCreate(db);
        }
    }
 
    public DBAdapter open()
    {
        db = DBHelper.getWritableDatabase();
 
        return this;
    }
 
    public void close()
    {
        db.close();
    }
 
    public void truncate()
    {
        db.execSQL("DELETE FROM produits");
    }
 
    public long insererUnProduit(String codeBarre, String titre, String Description)
    {
        ContentValues values = new ContentValues();
        values.put("codeBarre", codeBarre);
        values.put("titre",titre);
        values.put("description", Description);
 
        return db.insert("produits",null, values);
    }
 
    public boolean supprimerProduit(long id)
    {
        return db.delete("produits", "id = "+id, null) >0;
    }
 
    public Cursor recupererLaListeDesProduits()
    {
        return db.query("produits", new String[]{
                "_id",
                "codeBarre",
                "titre",
                "description"
        }, null, null, null, null, null);
    }
}
Le problème est qu'au moment où je clique sur le bouton Ajouter, le message suivant apparaît dans le Logcat :
05-01 00:18:03.697: I/TTT(1580): column 'codeBarre' does not exist
Quelqu'un saurait-il m'expliquer ce qui ne va pas ?

Merci d'avance pour votre aide.