Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android Sqlite
In my app i track the user consumed calories ,and when iam trying to retrieve the daily needed calories counter from my sqlite data base it returned as zero , but when i debug my app line by line the initialization and update of the counter value is done correctly and it have a value " not zero" , why its returned as zero ? is there error in the way i returned it ? please help me
 
update code
<pre lang="java">
// update Daily needed cals Counter and other nutrients counters
        DBAdapter    db=new  DBAdapter(SaveMeal.this);
        db.open();
 
        String date = db.getDate(FormateDate());
        if(date.equals("not exist"))// first  save in the data base in this day 
        {
            long d =db.InitializeCounters(FormateDate());
 
            Log.e("intialize tracker counters" ,d+"inserted ?");
            boolean  st_result=db.UpdateNutrientsCounters(FormateDate(),Meal.MealTotalCalories,Meal.VB12_COUNTER,Meal.PROTEIN_COUNTER,
                    Meal.SODIUM_COUNTER,Meal.IRON_COUNTER, Meal.CHOLESTEROL_COUNTER,Meal.FAT_SAT_COUNTER,Meal.FAT_MONO_COUNTER);
            if(st_result)
                Log.e("NCals counter update after intialize ","done ");
            else
                Log.e("NCals counter update after intialize","failure  ");      
        }
        else if(date.equals(FormateDate()))
        {
            boolean  st_result=db.UpdateNutrientsCounters(FormateDate(),Meal.MealTotalCalories,Meal.VB12_COUNTER,Meal.PROTEIN_COUNTER,
                    Meal.SODIUM_COUNTER,Meal.IRON_COUNTER, Meal.CHOLESTEROL_COUNTER,Meal.FAT_SAT_COUNTER,Meal.FAT_MONO_COUNTER);
            if(st_result)
                Log.e("NCals counter update","done ");
            else
                Log.e("NCals counter update","failure  ");  
        }  
 
        db.close();
 

the retrieve method
 
public int getDNCalsCounter(String  date ) throws SQLException
        {   
            int NCals_CounterVal=0;
            Cursor cursor=db.query(true,TRACKER_TABLE_NAME, new String[]{KEY_DAILY_NCALS_COUNTER},  KEY_DATE+ " = '" + date + "'", null, null, null, null,null);
            if ( cursor .moveToFirst()) {
                NCals_CounterVal =cursor.getInt(cursor.getColumnIndex(KEY_DAILY_NCALS_COUNTER));
 
                  }
             cursor.close();
             cursor.deactivate();
            return NCals_CounterVal ;
        }   
 
Here where i use the retrieve method and it returns the counter as zero
 
remaining_cals_ToConsume_TV=(TextView)findViewById(R.id.RCTC_value);
 
     db = new DBAdapter(this);
    db.open();
 
    NCals_counter=db.getDNCalsCounter(FormatDate());
    Log.e("NCals_counter" ,NCals_counter +" ");
    determined_DNcals=StaticPreferences.getDailyNeededCals(this);
    Log.e("determined_DNcals" ,determined_DNcals +" ");
    RCals_ToConsume=determined_DNcals-NCals_counter;
    remaining_cals_ToConsume_TV.setText(RCals_ToConsume +" cal");
    db.close();
 

 
FormatDate method
 

 
private String  FormatDate()
	{   
 
		localCalendar = Calendar.getInstance();
		return new  SimpleDateFormat("EEEE, d/MMM/yyyy").format(localCalendar.getTime());
 
	}
 
Posted 18-Jun-12 12:20pm
Comments
nice dream at 18-Jun-12 21:56pm
   
please any body can help me

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi dude..
Try this tutorial. I hope it will help you...
 
Click Here
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100