This is on my selectedDayChange on my mainactivity.java
date= year +""+ month +""+ dayOfMonth;
allfood food = new allfood();
food.Date="DATE_"+date;
double a = repo.totalFat(food);
Toast.makeText(getApplicationContext(), "" +a, Toast.LENGTH_LONG).show();
While this is on my repo.java
public double totalFat(allfood date){
SQLiteDatabase db = dbHelper1.getReadableDatabase();
String query = "SELECT SUM(Fat) FROM " +allfood.TABLE+ " WHERE " +KEY_Date+"="+date;
Cursor c = db.rawQuery(query, null);
c.moveToFirst();
double i=c.getDouble(0);
return i;
}
Then it shows an error, by the way, I know I needed to make something like this: KEY_Date+"='"+date+"'"
String query = "SELECT SUM(Fat) FROM " +allfood.TABLE+ " WHERE " +KEY_Date+"='"+date+"'";
android.database.sqlite.SQLiteException: near ".": syntax error (code 1): , while compiling: SELECT SUM(Fat) FROM allfood WHERE Date=info.androidhive.navigationdrawer.Overall.allfood@1cbb35e1
This line
Date=info.androidhive.navigationdrawer.Overall.allfood@1cbb35e1
should be
Date=DATE_20170213
How can I fix this?