lundi 7 mars 2016

Public cursor cannot resolve symbol

So I am trying to get all the information a SQL database I created and display it in a listview however I am coming up against an error "cannot resolve symbol TABLE_NAME" even though it is defined as public static string at the top of the page.

public class database_helper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "food_diary.db";
public static final String TABLE_NAME = "entries_table";

public static final String COL_1 = "ID";
public static final String COL_2 = "MEAL";
public static final String COL_3 = "FOODNAME";
public static final String COL_4 = "SYNS";
public static final String COL_5 = "HEXA";
public static final String COL_6 = "HEXB";
public static final String COL_7 = "FREEFOOD";
public static final String COL_8 = "FIBRE";
public static final String COL_9 = "PROTEIN";
public static final String COL_10 = "SPEEDFOOD";




public database_helper(Context context) {
    super(context, DATABASE_NAME, null, 1);

}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, MEAL TEXT, FOODNAME TEXT, SYNS INTEGER DEFAULT 0, HEXA REAL DEFAULT 0, HEXB INTEGER DEFAULT 0, FREEFOOD INTEGER DEFAULT 0, FIBRE INTEGER DEFAULT 0, PROTEIN INTEGER DEFAULT 0, SPEEDFOOD INTEGER DEFAULT 0)");

}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME);
    onCreate(db);
}


public boolean insertData(String meal, String foodname, int syns, float  hexa, float hexb, int freefood, int fibre, int protein, int Speedfood) {

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_2, meal);
    contentValues.put(COL_3, foodname);
    contentValues.put(COL_4, syns);
    contentValues.put(COL_5, hexa);
    contentValues.put(COL_6, hexb);
    contentValues.put(COL_7, freefood);
    contentValues.put(COL_8, fibre);
    contentValues.put(COL_9, protein);
    contentValues.put(COL_10, Speedfood);

    long result = db.insert(TABLE_NAME, null, contentValues);

    if (result == -1)
        return false;
    else
        return true;

}

public Cursor getAllData(SQLiteDatabase db) {
    String[] projections = {COL_1,COL_2,COL_3,COL_4,COL_5,COL_6,COL_7,COL_8,COL_9,COL_10};
    Cursor cursor = db.query(COL_1.TABLE_NAME, projections, null, null, null, null, null);
    return cursor;
}

}

Aucun commentaire:

Enregistrer un commentaire