1
Iam嘗試從我的sqlite數據庫的最後一行獲取值,並將其用於我的主要活動中的乘法和除法以獲得特定結果。但是我得到乘法結果爲0,除法結果爲「無窮大」。誰能幫忙!Android - 從「SQL Anywhere數據庫」中提取的值乘以「infinity」時的值結果
繼承人的代碼
food.java (main activity)
{
//user inputs
ETRate = (EditText)findViewById(R.id.ETRate);
ETFoodQty =(EditText)findViewById(R.id.ETFoodQty;
ETRate.setOnFocusChangeListener(this);
ETFoodQty.setOnFocusChangeListener(this);
FoodStorage foodGetInfo = new FoosStorage(this);
foodGetInfo.open();
foodGetInfo.getAvgTotal(this);
foodGetInfo.close();
chkLastTotal1.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
isChkLastTotal1=true;
}
});
public void onFocusChange(View predictionFocusView, boolean hasPredictionETFocus)
{
if(ETRate.isFocused())
{
if(foodQty!=0) //here I get rate =0
{
rate =(long) (lastTotal*foodQty);
setRate(rate);
ETRate.setText(String.valueOf(rate));
}
}
else if(foodQty.isFocused()) //Here I get foodQty = infinity
{
if(rate!=0)
{
foodQty =rate/avgtotal;
setPredictFoodQty(foodQty);
ETfoodQty.setText(String.valueOf(foodQty));
}
}
foodStorage.java (database file)
public void getAvgtotal(food pd)
{
String [] columns = new String[]{KEY_ROW_ID, KEY_RATE, KEY_FOOD_QTY, KEY_FOOD_PRICE, KEY_QUALITY, KEY_TOTAL, KEY_DATE,KEY_GRADE};
if(pd.isChkLastTotal1()==true)
{
Cursor c= ourDatabase.rawQuery("SELECT * FROM food_table ORDER BY _id DESC LIMIT 1", null);
c.moveToFirst();
if(c!=null && c.getCount()>0)
{
c.moveToLast();
String getLastTotal =c.getString(5);
food myFoodInfo = new Food();
myFoodInfo.setavgTotal(Double.parseDouble(getLastTotal));
}
c.close();
}
}
1)如果你只需要一列的話在查詢中詢問這個列(否則你必須希望第五列真的是你想要的那一列)2)如果值作爲數據庫中的浮點數存儲,不要把它作爲字符串取出。如果值被存儲爲字符串,那爲什麼? 3)可能有不同的小數點 –
Thanx答覆。事情是Iam從數據庫中獲取數據,但是當我嘗試乘以或除以從用戶獲得的值時,我得到0和無窮大。無法弄清楚爲什麼? –
請發佈代碼您從哪裏獲得用戶的價值! –