mardi 19 mai 2015

Getting NullPointerExeption When reading Image from sqlite to array

this is my code to get image from db and put them into a drawable array

Table Structure:

_id INTEGER, question BLOB, answer1 BLOB, answer2 BLOB, answer3 BLOB, answer4 BLOB, answer5 BLOB, answer6 BLOB, asnwer7 BLOB, answer8 BLOB

and this my code:

public BitmapDrawable[][] getTableImage(String tbl_name) {

        qb.setTables(tbl_name);
        Cursor cursor = qb.query(db, null, null, null, null, null, null);
        int count = cursor.getCount();
        int count_column =cursor.getColumnCount()-1;
        BitmapDrawable[][] RavenQuery = new BitmapDrawable[count][count_column];

        cursor.moveToFirst();
        for (int i = 0; i < count; i++) {
            for (int j = 1; j < count_column; j++) {

// J start form 1 because 0 is _id

                byte[] blob = cursor.getBlob(j);

                Log.i("blob.lentgh",String.valueOf(blob.length));
                ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
                Log.i("InputStream.lentgh",inputStream.toString());
                Bitmap bitmap = BitmapFactory.decodeStream(inputStream);


                if (bitmap==null){
                    RavenQuery[i][j-1]=RavenQuery[0][0];
                    continue;}




                RavenQuery[i][j-1] = new BitmapDrawable(bitmap);
                      0,currentAccount.accImage.length));

            }
            cursor.moveToNext();
        }
        Log.w("Len", String.valueOf(RavenQuery.length));
        Log.w("b", "b = " +String.valueOf(RavenQuery[0][0].getBounds().height()) );
        cursor.close();
        Log.w("a", "a = " + String.valueOf(RavenQuery[0][0].getBounds().height()));
        return RavenQuery;
    }

when i call this function, it returns a drawable array with length of 60.

final Drawable[][] tbl_raven = sqlDb.getTableImage("tbl_t_reven");
        numberOfQuestions = tbl_raven.length;
        Log.w("height", "H = " + tbl_raven[0][0].getBounds());
        Log.w("lenreven", String.valueOf(numberOfQuestions));
        questionString = null;
        for (int i = 0; i < numberOfQuestions; i++) {
        CaseImages[i][0] = tbl_raven[i][0];
        CaseImages[i][1] = tbl_raven[i][1];
        CaseImages[i][2] = tbl_raven[i][2];
        CaseImages[i][3] = tbl_raven[i][3];
        CaseImages[i][4] = tbl_raven[i][4];
        CaseImages[i][5] = tbl_raven[i][5];
        CaseImages[i][6] = tbl_raven[i][6];
        CaseImages[i][7] = tbl_raven[i][7];
        CaseImages[i][8] = tbl_raven[i][8];
    }

but every cell is null???

Aucun commentaire:

Enregistrer un commentaire