Click here to Skip to main content
15,889,833 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

Java
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

Java
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


Java
private String  FormatDate()
	{   

		localCalendar = Calendar.getInstance();
		return new  SimpleDateFormat("EEEE, d/MMM/yyyy").format(localCalendar.getTime());

	}
Posted
Comments
nice dream 18-Jun-12 21:56pm    
please any body can help me

1 solution

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

Click Here
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900