Android - 当从SQLite数据库获取的值乘以值时,结果为“无穷大”

时间:2013-07-20 11:42:47

标签: android sqlite

我试图从我的sqlite数据库中的最后一行获取一个值,并将其用于我的主要活动中的乘法和除法以获得某个结果。但是我得到乘法结果为0,除法结果为“无穷大”。谁能帮忙!!

继承人的代码

 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 个答案:

答案 0 :(得分:0)

这里

food myFoodInfo = new Food();  
myFoodInfo.setavgTotal(Double.parseDouble(getLastTotal));

您正在创建新的食物对象

为什么不将值设置为pd传递到这里:

public void getAvgtotal(food pd)