How to transfer from the service image format of BLOB field of the database in ImageView android device?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
Do the following application:
There is some SQlite dB on the server, it has a table and the table is a picture(code below):
CREATE TABLE test (rowid INTEGER PRIMARY KEY AUTOINCREMENT, num1 REAL, num2 REAL, REAL num3, num4 REAL, picture BLOB); INSERT INTO test (num1, num2, num3, num4, picture) VALUES(1.1, 1.2, 1.3, 1.4, readfile('download.png'));

Server is Tomcat, which is using the service selects the picture from the DB and gives it in Json format:
private JSONArray getDbDataInJsonArrayFormat() { String sql = "SELECT rowid, num1, num2, num3, num4, picture FROM test"; try (Connection conn = this.connect(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql)) { JSONArray jsonResult = new JSONArray(); while ( { JsonRow JSONObject = new JSONObject(); jsonRow.accumulate("picture", rs.getString("picture")); jsonResult.put(jsonRow); } return jsonResult; } catch (SQLException e) { LOG.error(e.getMessage()); return null; } }

Android connects to the service, shakes Json, puts a picture in your DB:
try { db.beginTransaction(); for (int i = 0; i < response.length(); i++) { JsonRow JSONObject = response.getJSONObject(i); String picture = jsonRow.getString("picture"); ContentValues values = new ContentValues(); values.put(Test.PICTURE, picture); db.insert(TEST, null, values); } db.setTransactionSuccessful(); } catch (Exception e) { Log.w("Error: ", e); } finally { db.endTransaction(); }

Then I do a row fetch from the DB, trying to form a BLOB, but nothing happens:
public Cursor getAllDataFromTestTable() { SQLiteDatabase db = mDbOpenHelper.getWritableDatabase(); String table = TEST; Cursor c = db.query(table, null, null, null, null, null, null); if (c != null) { c.moveToFirst(); } return c; } public static List getResultStringListAndClose(Cursor c) { final List resultStringList = getAllDataFromDB(c); closeCursor(c); return resultStringList; } private void onDataLoadedFromDb(Cursor c) { List resList = DbUtils.getResultStringListAndClose(c); for (int i = 0; i < resList.size(); ++i) { ContentValues "rowValues" = resList.get(i); // picture ImageView picture = new ImageView(this); byte[] encodeByte = "rowValues".getAsByteArray(DbContract.Test.PICTURE); Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); picture.setImageBitmap(Bitmap.createScaledBitmap(bitmap, picture.getWidth(), picture.getHeight(), false)); } }

Bitmap variable is null.
Can you please tell me what this error is or how to do my task?
by | 12 views

Please log in or register to answer this question.

Related questions

0 like 0 dislike
6 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
35,456 users