samedi 11 avril 2015

App craches 'attempt to invoke virtual method'

My app craches when i try to update my database it gives me the following problem



attempt to invoke virtual method 'android.database.cursor com.leoni.bd.Gestion_db.FindDate(java.lang.String)' on a null object reference



i couldn't find the null object i tried many things but it didn't work ! i need help please !


this is my Gestion_db.java class



private SQLiteDatabase _myDbm;

public Gestion_db(Context pContext) {

SqliteCreator s = new SqliteCreator(pContext, Stat.DB_NAME, null, 1);

_myDbm = s.getWritableDatabase();
}

public void close() {
_myDbm.close();
}

public Cursor FindDate(String Attribute) {
String query = "SELECT * FROM " +Stat.TABLE_NAME +" WHERE ? LIKE '%?%' ";
return _myDbm.rawQuery(query, new String[] {Stat.COL_DATE,Attribute});

}


this is the method from my Controle.java activity wich contain the cursor



//header of the activity
private Gestion_db _myGestionDB;
private String _myRecognizedText = null;

// Mise à jour de la base de données quelque soit l'action
private void MiseAJour() {

String dateCourante = new SimpleDateFormat("yyyy:MM:dd",Locale.getDefault()).format(new Date());
Boolean existe=false;

Cursor c = _myGestionDB.FindDate(dateCourante);

if (c.getCount() != 0) {

c.moveToFirst();

while (!c.isAfterLast()) {


String ldate = c.getString(c.getColumnIndex(Stat.COL_DATE));
String lMatricule = c.getString(c.getColumnIndex(Stat.COL_TEXTE_OCR));

if (ldate.equals(dateCourante)&& lMatricule.equals(_myRecognizedText)) {
existe=true;
break;

}
c.moveToNext();

}



}

if (existe){
UpdateHeure(_myHeure);

}else{
AddVoyage();
}

}


this ic Stat.java class wich contains some Strings



public class Stat {
public static final String DB_NAME = "leoni.db";
public static final String URL_CHECK = "http://ift.tt/1Fzg5OS";
public static final String GET_URL = "http://ift.tt/1DywWV6";
public static final String COL_ID = "_id";

// Gestion des déplacements
public static final String TABLE_NAME = "gestion_des_deplacements";
public static final String COL_TEXTE_OCR = "texte_ocr";
public static final String COL_DATE = "date";
public static final String COL_HEURE_DEPART = "heure_depart";
public static final String COL_HEURE_ARRIVEE = "heure_arrive";
public static final String CREATE_TABLE_DEPLACEMENTS = "CREATE TABLE "
+ Stat.TABLE_NAME + " (" + Stat.COL_ID
+ " INTEGER PRIMARY KEY autoincrement," + Stat.COL_TEXTE_OCR
+ " VARCHAR(40)" + "," + Stat.COL_CHAUFFEUR + " VARCHAR(50)" + ","
+ Stat.COL_DATE + " VARCHAR(50)" + "," + Stat.COL_HEURE_DEPART
+ " VARCHAR(30)" + "," + Stat.COL_HEURE_ARRIVEE + " VARCHAR(30));";

// Gestion des chauffeurs
public static final String COL_MATRICULE = "matricule";
public static final String COL_CHAUFFEUR = "chauffeur";

}

Aucun commentaire:

Enregistrer un commentaire