2

私のsqliteデータベースで列の平均を見つけようとしています。コードは次のとおりです。

public void getAvgMileage(Prediction pd) 
    {

    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 AVG(_mileage) FROM fuel_table WHERE _mileage IS NOT NULL ORDER BY _id DESC LIMIT 5", null);
                predictionCursor.moveToFirst();
                if(predictionCursor!=null && predictionCursor.getCount()>0)
                {
                    predictionCursor.moveToLast();
                   findAvgMileage = (Double.valueOf(predictionCursor.toString()));
                    pd.setpredictionMileage(findAvgMileage);
                }
}

しかし、私は NullPointerException を取得しています。何か助けて?? ありがとうございました。

4

1 に答える 1