问题描述
在我的应用程序中,我跟踪用户消耗的卡路里,并且当我试图从我的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方法
FormatDate method
private String FormatDate()
{
localCalendar = Calendar.getInstance();
return new SimpleDateFormat("EEEE, d/MMM/yyyy").format(localCalendar.getTime());
}
推荐答案
这篇关于数据成功插入到我的sqlite数据库中,但是当我返回它时,它没有返回存储的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!