title: Sqlite in android studio 2.2
body: <p>I am getting error in writing query get error at DESC in function getfood.Here is my exception.</p>
  
  <p><strong>Exception:</strong></p>
  
  <p><em>beginning of crash</em></p>
  
  <pre><code>    E/AndroidRuntime: FATAL EXCEPTION: main
  
        Process: com.app.caloriescounter.admin.caloriescounter, PID: 2759
                        java.lang.RuntimeException: Unable to start activity 
      ComponentInfo{com.app.caloriescounter.admin.caloriescounter/com.app.caloriesc
      ounter.admin.caloriescounter.Main2Activity}: 
      java.lang.IllegalArgumentException: **invalid LIMIT clauses: DESC** 
               at 
      android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                            at 
      android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                            at android.app.ActivityThread.-wrap11(ActivityThread.java)
                            at 
      android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
       at android.os.Handler.dispatchMessage(Handler.java:102)
                            at android.os.Looper.loop(Looper.java:148)
                            at 
      android.app.ActivityThread.main(ActivityThread.java:5417)
                            at java.lang.reflect.Method.invoke(Native Method)
                            at 
      com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                            at 
      com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                         Caused by: java.lang.IllegalArgumentException: invalid LIMIT clauses: DESC 
                            at 
      android.database.sqlite.SQLiteQueryBuilder.buildQueryString(SQLiteQueryBuilde
      r.java:209)
                            at 
     android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1160)
                            at 
      android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
                            at 
      android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1240)
                            at 
      data.Databasehandler.getfood(Databasehandler.java:86)
                            at 
  com.app.caloriescounter.admin.caloriescounter.Main2Activity.refreshdata(Main2Activity.java:38)
                            at com.app.caloriescounter.admin.caloriescounter.Main2Activity.onCreate(Main2Activity.java:32)
                            at android.app.Activity.performCreate(Activity.java:6237)
                            at 
      android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                            at 
      android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                            at 
      android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  
                            at android.app.ActivityThread.-
      wrap11(ActivityThread.java) 
                            at 
      android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                            at 
      android.os.Handler.dispatchMessage(Handler.java:102) 
                            at android.os.Looper.loop(Looper.java:148) 
                            at 
      android.app.ActivityThread.main(ActivityThread.java:5417) 
  </code></pre>
  
  <p>this is my <strong>Source Code:</strong> of <code>Databasehandler</code> class.</p>
  
  <pre><code>    package data;
      import android.content.ContentValues;
      import android.content.Context;
      import android.database.Cursor;
      import android.database.sqlite.SQLiteDatabase;
      import android.database.sqlite.SQLiteOpenHelper;
      import android.util.Log;
      import java.text.DateFormat;
      import java.util.ArrayList;
      import java.util.Date;
      import model.Food;
  
      /**
       * Created by Admin on 9/10/2016.
       */
      public class Databasehandler extends SQLiteOpenHelper {
          private static final String LOGCAT = null;
          private final ArrayList&lt;Food&gt; foodArrayList=new ArrayList&lt;&gt;();
          public Databasehandler(Context context) {
              super(context,Constsnts.databasename,null,Constsnts.databaseversion);
              Log.d(LOGCAT,"Database Created");
          }
          @Override
          public void onCreate(SQLiteDatabase sqLiteDatabase) {
      String Crete_Table="CREATE TABLE "+ Constsnts.food_table+" ( " + 
      Constsnts.KeyId +"INTEGER PRIMARY KEY, " + Constsnts.food_name +"TEXT, "
              +Constsnts.foodcalories +"INT , "+Constsnts.datename +"LONG );";
          sqLiteDatabase.execSQL(Crete_Table);
          }
          @Override
          public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
      sqLiteDatabase.execSQL("DROP TABLE IF EXISTS "+Constsnts.food_table);
          //new one
              onCreate(sqLiteDatabase);
          }
          //item all
          public int getTotalitem(){
              int totalitem=0;
              String query=" SELECT * FROM "+Constsnts.food_table;
              SQLiteDatabase db=this.getReadableDatabase();
              Cursor cursor=db.rawQuery(query,null);
              totalitem=cursor.getCount();
              cursor.close();
              return totalitem;
          }
      public  int Caloriesall(){
              int calories=0;
              String query="SELECT SUM ( "+Constsnts.foodcalories +")"+"FROM 
      "+Constsnts.food_table;
              SQLiteDatabase db=this.getReadableDatabase();
              Cursor cursor=db.rawQuery(query,null);
              if(cursor.moveToNext()){
                  calories=cursor.getInt(0);
              }
              cursor.close();
              db.close();
              return  calories;
          }
          //deletefood
          public void deletefood(int id){
             SQLiteDatabase db=this.getWritableDatabase();
              db.delete(Constsnts.food_table,Constsnts.KeyId+" =? ",new String[]
      {String.valueOf(id)});
              db.close();
          }
          //add food
          public void addfood(Food food){
          SQLiteDatabase db=this.getWritableDatabase();
          ContentValues values=new ContentValues();
          values.put(Constsnts.food_name,food.getFoodname());
              values.put(Constsnts.foodcalories,food.getCaleries());
              values.put(Constsnts.datename,System.currentTimeMillis());
              db.insert(Constsnts.food_table,null,values);
              Log.v("Added food item","yess");
              db.close();
          }
          //get all food
          public ArrayList&lt;Food&gt; getfood(){
              foodArrayList.clear();
              SQLiteDatabase db=this.getReadableDatabase();
              Cursor cursor=db.query(Constsnts.food_table,new String[]
      {Constsnts.KeyId,Constsnts.databasename,
  Constsnts.foodcalories,Constsnts.datename},null,null,null,null,Constsnts.datename," DESC ");
              if(cursor.moveToFirst()){
                  do {
                      Food food=new Food();
      food.setFoodname(cursor.getString(cursor.getColumnIndex(Constsnts.food_name)));
      food.setCaleries(cursor.getInt(cursor.getColumnIndex(Constsnts.foodcalories)));
      food.setFoodid(cursor.getInt(cursor.getColumnIndex(Constsnts.KeyId)));
                      DateFormat dateFormat=DateFormat.getDateInstance();
                      String data=dateFormat.format(new 
      Date(cursor.getLong(cursor.getColumnIndex(Constsnts.datename))).getTime());
                      food.setRecorddate(data);
                      foodArrayList.add(food);
                  }while(cursor.moveToNext());
              }
      cursor.close();
              db.close();
              return foodArrayList;
          }
      }
  </code></pre>
  
  <p>Thanks in advance.</p>