iam trying find average of values in column in sqlite database. column has null , not null values. need calculate average of based on last 1, 5 or 10 not null values. when try fetch data through query cursor null. kindly help. heres code fetching last not null value of mileage.
public void calculateavgmileage(prediction predictmileage) { if(predictmileage.ischklastmileage1()==true) { string [] columns = new string[]{key_row_id, key_km, key_fuel_qty, key_fuel_price, key_total_cost, key_mileage, key_date,key_tank_full}; predictioncursor = ourdatabase.rawquery("select * fuel_table order _id desc limit 1", null); if(predictioncursor!=null && predictioncursor.getcolumncount()>0) { predictioncursor.movetolast(); string predictionmileage= predictioncursor.getstring(5); if(predictionmileage==null) { predictioncursor.movetoprevious(); } else { avgmileageprediction.setpredictionmileage(double.valueof(predictionmileage)); } }
you cannot read count of columns before have forced cursor read data call movetofirst or similar function.
Comments
Post a Comment