Problème de reconaissance de colunm SQLITE

Fermé
StalkerXIII - 27 avril 2016 à 12:40
 StalkerXIII - 27 avril 2016 à 19:48
Bonjour j'ai un problème quand je compile mon application :

La bdd :
package com.example.simon.applicationbasket;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class bdd {

public static final String KEY_ROWID = "_id";
public static final String KEY_PRENOM = "prenom";// Prénom du joueur
public static final String KEY_NOM = "nom"; // Nom du joueur

public static final String KEY_EQUIPE_ID = "equipe"; // ID de l'équpie
//utlisé dans joueur.xml
//info personnelles
public static final String KEY_MAILLOT = "maillot"; // numéro de maillot joueur
public static final String KEY_BIRTH = "naissance"; // date de naissance joueur
//public static final String KEY_PHOTO = "photo"; // photo du joueur à implémenter dans le futur
//Stats dans le match
public static final String KEY_DECISIV = "decisiv"; // nombre de passes decisives à l'année
public static final String KEY_REBONDS = "rebonds"; // nombre de rebonds à l'annee
public static final String KEY_MATCH = "match"; // nombre de matchs joués
public static final String KEY_INTERCEPT = "intercept"; // nombre d'interceptions
public static final String KEY_CONTRES = "contres"; // nombre de contre effectués
public static final String KEY_PERTEBALLE = "perte"; // nombre de balles perdues
public static final String KEY_FAUTES = "fautes"; //nombre de fautes commises
public static final String KEY_ESSAI2 = "essai2"; // nombre d'essai à 2pts
public static final String KEY_ESSAI3 = "essai3"; // nombre d'essai à 3pts
public static final String KEY_ESSAILF = "essailf"; //nombre d'essai de lancés francs
public static final String KEY_2PTS = "deuxpts"; // nombre de 2pts réussis
public static final String KEY_3PTS = "troispts"; // nombre de 3pts réussis
public static final String KEY_LF = "lf"; // nombre de lancés francs
//fin

private static final String TAG = "bdd";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;

private static final String DATABASE_NAME = "Basket";
private static final String SQLITE_TABLE = "Joueur";
private static final int DATABASE_VERSION = 1;

private final Context mCtx;

private static final String DATABASE_CREATE =
"CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
KEY_ROWID + " integer PRIMARY KEY autoincrement," +
KEY_PRENOM + "TEXT," +
KEY_NOM + "TEXT," +
KEY_EQUIPE_ID + "TEXT," +
KEY_MAILLOT + "TEXT," +
KEY_BIRTH + "TEXT," +
KEY_DECISIV + "TEXT,"+
KEY_REBONDS + "TEXT," +
KEY_MATCH + "TEXT," +
KEY_INTERCEPT + "TEXT," +
KEY_CONTRES + "TEXT," +
KEY_PERTEBALLE + "TEXT," +
KEY_FAUTES + "TEXT," +
KEY_ESSAI2 + "TEXT," +
KEY_ESSAI3 + "TEXT," +
KEY_ESSAILF + "TEXT," +
KEY_2PTS + "TEXT," +
KEY_3PTS + "TEXT," +
KEY_LF + "TEXT," +
" UNIQUE (" + KEY_ROWID +"));";

private static class DatabaseHelper extends SQLiteOpenHelper {

DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


@Override
public void onCreate(SQLiteDatabase db) {
Log.w(TAG, DATABASE_CREATE);
db.execSQL(DATABASE_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + SQLITE_TABLE);
onCreate(db);
}
}

public bdd(Context ctx) {
this.mCtx = ctx;
}

public bdd open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}

public void close() {
if (mDbHelper != null) {
mDbHelper.close();
}
}

public long createJoueur(String prenom, String nom,
String equipe, String maillot, String birth, String decisiv, String rebonds, String match, String intercept, String contres,
String perteballe, String fautes, String essai2, String essai3, String essailf, String deuxpts, String troispts, String lf) {

ContentValues initialValues = new ContentValues();
initialValues.put(KEY_PRENOM, prenom);
initialValues.put(KEY_NOM, nom);
initialValues.put(KEY_EQUIPE_ID, equipe);
initialValues.put(KEY_BIRTH, birth);
initialValues.put(KEY_MAILLOT, maillot);
initialValues.put(KEY_DECISIV, decisiv);
initialValues.put(KEY_REBONDS, rebonds);
initialValues.put(KEY_MATCH, match);
initialValues.put(KEY_INTERCEPT, intercept);
initialValues.put(KEY_CONTRES, contres);
initialValues.put(KEY_PERTEBALLE, perteballe);
initialValues.put(KEY_FAUTES, fautes);
initialValues.put(KEY_ESSAI2, essai2);
initialValues.put(KEY_ESSAI3, essai3);
initialValues.put(KEY_ESSAILF, essailf);
initialValues.put(KEY_2PTS, deuxpts);
initialValues.put(KEY_3PTS, troispts);
initialValues.put(KEY_LF, lf);


return mDb.insert(SQLITE_TABLE, null, initialValues);
}

public boolean deleteAllJoueur() {

int doneDelete = 0;
doneDelete = mDb.delete(SQLITE_TABLE, null , null);
Log.w(TAG, Integer.toString(doneDelete));
return doneDelete > 0;

}

public Cursor fetchJoueurByName(String inputText) throws SQLException {
Log.w(TAG, inputText);
Cursor mCursor = null;
if (inputText == null || inputText.length () == 0) {
mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_PRENOM,
KEY_NOM, KEY_EQUIPE_ID, KEY_BIRTH,
KEY_MAILLOT,
KEY_DECISIV,
KEY_REBONDS,
KEY_MATCH,
KEY_INTERCEPT,
KEY_CONTRES,
KEY_PERTEBALLE,
KEY_FAUTES,
KEY_ESSAI2,
KEY_ESSAI3,
KEY_ESSAILF,
KEY_2PTS,
KEY_3PTS,
KEY_LF},
null, null, null, null, null);

}
else {
mCursor = mDb.query(true, SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_PRENOM,
KEY_NOM, KEY_EQUIPE_ID, KEY_BIRTH,
KEY_MAILLOT,
KEY_DECISIV,
KEY_REBONDS,
KEY_MATCH,
KEY_INTERCEPT,
KEY_CONTRES,
KEY_PERTEBALLE,
KEY_FAUTES,
KEY_ESSAI2,
KEY_ESSAI3,
KEY_ESSAILF,
KEY_2PTS,
KEY_3PTS,
KEY_LF},
KEY_EQUIPE_ID + " like '%" + inputText + "%'", null,
null, null, null, null);
}
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;

}

public Cursor fetchAllJoueurs() {

Cursor mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_PRENOM,
KEY_NOM, KEY_EQUIPE_ID, KEY_BIRTH,
KEY_MAILLOT,
KEY_DECISIV,
KEY_REBONDS,
KEY_MATCH,
KEY_INTERCEPT,
KEY_CONTRES,
KEY_PERTEBALLE,
KEY_FAUTES,
KEY_ESSAI2,
KEY_ESSAI3,
KEY_ESSAILF,
KEY_2PTS,
KEY_3PTS,
KEY_LF},
null, null, null, null, null);

if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}

public Cursor fetchJoueurs() {

Cursor mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_PRENOM,
KEY_NOM, KEY_EQUIPE_ID, KEY_BIRTH,
KEY_MAILLOT,
KEY_DECISIV,
KEY_REBONDS,
KEY_MATCH,
KEY_INTERCEPT,
KEY_CONTRES,
KEY_PERTEBALLE,
KEY_FAUTES,
KEY_ESSAI2,
KEY_ESSAI3,
KEY_ESSAILF,
KEY_2PTS,
KEY_3PTS,
KEY_LF},
null, null, null, null, null);

if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}

public void insertJoueur() {

createJoueur("nom","prenom","equipe","5","12/12/12","52","4","20","15","1","4","10","45","12","14","45","60","10");
createJoueur("James","LeBron","Cleveland Cavaliers","23","30/12/84","511","416","69","109","49","272","135","339","940","528","504","120","375");
createJoueur("Irving","Kyrie","Cleveland Cavaliers","0","23/03/92","389","237","75","114","20","186","146","378","857","365","421","157","315");
createJoueur("Love","Kevin","Cleveland Cavaliers","3","07/09/88","168","731","75","51","39","122","140","392","560","321","269","144","258");

}


}


Le main :

package com.example.simon.applicationbasket;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FilterQueryProvider;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;


@SuppressLint("NewApi")
public class MainActivity extends Activity {
private bdd dbHelper;
private SimpleCursorAdapter dataAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbHelper = new bdd(this);
dbHelper.open();

//Clean all data
dbHelper.deleteAllJoueur();
//Add some data
dbHelper.insertJoueur();

displayListView();

}
private void displayListView() {


Cursor cursor = dbHelper.fetchAllJoueurs();

final String[] columns = new String[] {
bdd.KEY_PRENOM,
bdd.KEY_NOM,
bdd.KEY_EQUIPE_ID,
bdd.KEY_BIRTH,
bdd.KEY_MAILLOT,
bdd.KEY_DECISIV,
bdd.KEY_REBONDS,
bdd.KEY_MATCH,
bdd.KEY_INTERCEPT,
bdd.KEY_CONTRES,
bdd.KEY_PERTEBALLE,
bdd.KEY_FAUTES,
bdd.KEY_ESSAI2,
bdd.KEY_ESSAI3,
bdd.KEY_ESSAILF,
bdd.KEY_2PTS,
bdd.KEY_3PTS,
bdd.KEY_LF
};
final int[] to = new int[] {
R.id.prenom,
R.id.nom,
R.id.equipe,
R.id.naissance,
R.id.desisiv,
R.id.rebonds,
R.id.matchs,
R.id.intercept,
R.id.contres,
R.id.pertes,
R.id.fautes,
R.id.essai2,
R.id.essai3,
R.id.essaiLF,
R.id.deuxpts,
R.id.troispts,
R.id.lf
};

dataAdapter = new SimpleCursorAdapter(
this,
R.layout.layout_basket_info,
cursor,
columns,
to,
0);
// Afficher stats du joueur
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(dataAdapter);




listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView listView, View view,
int position, long id) {
dbHelper.fetchJoueurs();
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
setContentView(R.layout.joueur);
//String r1 = bdd.KEY_RANG;
TextView prenomviews = (TextView) findViewById(R.id.prenom);
TextView nomviews = (TextView) findViewById(R.id.nom);
TextView equipeviews = (TextView) findViewById(R.id.equipe);
TextView naissanceviews = (TextView) findViewById(R.id.naissance);
TextView desisivviews = (TextView) findViewById(R.id.desisiv);
TextView rebondsviews = (TextView) findViewById(R.id.rebonds);
TextView matchsviews = (TextView) findViewById(R.id.matchs);
TextView interceptviews = (TextView) findViewById(R.id.intercept);
TextView contresviews = (TextView) findViewById(R.id.contres);
TextView pertesviews = (TextView) findViewById(R.id.pertes);
TextView fautesviews = (TextView) findViewById(R.id.fautes);
TextView essai2views = (TextView) findViewById(R.id.essai2);
TextView essai3views = (TextView) findViewById(R.id.essai3);
TextView essaiLFviews = (TextView) findViewById(R.id.essaiLF);
TextView deuxviews = (TextView) findViewById(R.id.deuxpts);
TextView troisviews = (TextView) findViewById(R.id.troispts);
TextView LFviews = (TextView) findViewById(R.id.lf);
String JoueurNom =
cursor.getString(cursor.getColumnIndexOrThrow("nom"));
nomviews.setText(JoueurNom);
String JoueurPrenom =
cursor.getString(cursor.getColumnIndexOrThrow("prenom"));
prenomviews.setText(JoueurPrenom);
String JoueurEquipe =
cursor.getString(cursor.getColumnIndexOrThrow("equipe"));
equipeviews.setText(JoueurEquipe);
String JoueurNaissance =
cursor.getString(cursor.getColumnIndexOrThrow("naissance"));
naissanceviews.setText(JoueurNaissance);
String JoueurDesisiv =
cursor.getString(cursor.getColumnIndexOrThrow("desisive"));
desisivviews.setText(JoueurDesisiv);
String JoueurRebond =
cursor.getString(cursor.getColumnIndexOrThrow("rebonds"));
rebondsviews.setText(JoueurRebond);

}
});



// Fin du code

EditText myFilter = (EditText) findViewById(R.id.myFilter);
myFilter.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
}

public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}

public void onTextChanged(CharSequence s, int start,
int before, int count) {
dataAdapter.getFilter().filter(s.toString());
}
});

dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return dbHelper.fetchJoueurByName(constraint.toString());
}
});


}
}


L'érreur :

04-25 10:15:12.217 13256-13256/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.simon.applicationbasket, PID: 13256
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.simon.applicationbasket/com.example.simon.applicationbasket.MainActivity}: android.database.sqlite.SQLiteException: no such column: prenom (code 1): , while compiling: SELECT _id, prenom, nom, equipe, naissance, maillot, decisiv, rebonds, match, intercept, contres, perte, fautes, essai2, essai3, essailf, deuxpts, troispts, lf FROM Joueur
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5127)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such column: prenom (code 1): , while compiling: SELECT _id, prenom, nom, equipe, naissance, maillot, decisiv, rebonds, match, intercept, contres, perte, fautes, essai2, essai3, essailf, deuxpts, troispts, lf FROM Joueur
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at com.example.simon.applicationbasket.bdd.fetchAllJoueurs(bdd.java:201)
at com.example.simon.applicationbasket.MainActivity.displayListView(MainActivity.java:42)
at com.example.simon.applicationbasket.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5127)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
04-25 10:15:12.227 13256-13256/? I/Process: Sending signal. PID: 13256 SIG: 9



J'ai tout cherché je trouve pas, on doit rendre notre projet tut dans 1 mois
A voir également:

2 réponses

BunoCS Messages postés 15495 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 octobre 2024 3 909
27 avril 2016 à 14:23
Hello,

Dans ton
create_table
, i manque un espace avant les "Text":
KEY_PRENOM + "TEXT," +

devient
KEY_PRENOM + " TEXT," +

Et c'est partout pareil je pense
0
Bonjour, merci de la réponse, sur Openclassroom on m'a dit la même chose, j'ai modifié la ligne mais ça n'a rien changé :/
0
BunoCS Messages postés 15495 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 octobre 2024 3 909
27 avril 2016 à 17:38
Tu as TOUTES les lignes à changer, hein! ;)
0
Oui avec tout les " TEXT," je l'ai fais mais ça ne fonctionne pas, il me dis toujours qu'il ne reconnais pas la colonne "prenom"
0
private static final String DATABASE_CREATE =
"CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
KEY_ROWID + " integer PRIMARY KEY autoincrement," +
KEY_PRENOM + " TEXT," +
KEY_NOM + " TEXT," +
KEY_EQUIPE_ID + " TEXT," +
KEY_MAILLOT + " TEXT," +
KEY_BIRTH + " TEXT," +
KEY_DECISIV + " TEXT,"+
KEY_REBONDS + " TEXT," +
KEY_MATCH + " TEXT," +
KEY_INTERCEPT + " TEXT," +
KEY_CONTRES + " TEXT," +
KEY_PERTEBALLE + " TEXT," +
KEY_FAUTES + " TEXT," +
KEY_ESSAI2 + " TEXT," +
KEY_ESSAI3 + " TEXT," +
KEY_ESSAILF + " TEXT," +
KEY_2PTS + " TEXT," +
KEY_3PTS + " TEXT," +
KEY_LF + " TEXT," +
" UNIQUE (" + KEY_ROWID +"));";
0