vendredi 25 mars 2016

how android receive the result from a sqlite query?

I would like to execute a sqlite query and get the result from android, but it said that's a nullPoint==> Caused by: java.lang.NullPointerException

This is my sqlite query, it works in sqlite prompt:

 select count(tWORD.word) * 100.00/(select count(word) * 1.00 
   from tWORD)from tWORD inner join client_vocab 
ON client_vocab.word = tWORD.word;  

AND this is my android method:

public double percentKnowlege(){
        double percent;
        SQLiteDatabase db = database.getReadableDatabase();
        String sql = "select printf(\"%.2f\", " +
                "count(tWORD.word) * 100.00/(select count(word) * 1.00 from tWORD)) " +
                "from tWORD inner join client_vocab ON client_vocab.word = tWORD.word; ";
        Cursor cursor = db.rawQuery(sql,null);
        if (cursor.moveToFirst())
            percent = cursor.getDouble(0);
        else
            return -1;
        db.close();
        return percent;
    }

Aucun commentaire:

Enregistrer un commentaire