Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to create a Bitmap
    primarykey
    data
    text
    <p>Can anyone tell me why is the Bitmap not getting created?Please check the other code as well if i am doing something wrong.</p> <pre><code>HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("URL"); List&lt;NameValuePair&gt; list = new ArrayList&lt;NameValuePair&gt;(); list.add(new BasicNameValuePair("username",username)); UrlEncodedFormEntity urlencodedformentity = new UrlEncodedFormEntity(list); httppost.setEntity(urlencodedformentity); HttpResponse response = httpclient.execute(httppost); InputStream is = response.getEntity().getContent(); // following Bitmap is getting null Bitmap bm = BitmapFactory.decodeStream(new BufferedInputStream(is)); if(bm==null) { Toast.makeText(this,"Bitmap null", Toast.LENGTH_LONG).show(); } else { img.setImageBitmap(bm); } </code></pre> <p>Client side to send the image to server</p> <pre><code>Bitmap b = ((BitmapDrawable) img.getDrawable()).getBitmap(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); b.compress(CompressFormat.JPEG, 100, baos); byte ar[] = baos.toByteArray(); String s = Base64.encodeToString(ar, 0); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("URL"); List&lt;NameValuePair&gt; list = new ArrayList&lt;NameValuePair&gt;(); list.add(new BasicNameValuePair("username",username)); list.add(new BasicNameValuePair("image",s)); UrlEncodedFormEntity urlencodedformentity = new UrlEncodedFormEntity(list); httppost.setEntity(urlencodedformentity); HttpResponse response = httpclient.execute(httppost); BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); Toast.makeText(this, br.readLine(), Toast.LENGTH_LONG).show(); </code></pre> <p>Server side to retrieve and store the image</p> <pre><code>String username = req.getParameter("username"); resp.getWriter().write(username); try { byte[] image = req.getParameter("image").getBytes(); Blob profilepic = new Blob(image); Profile profile = new Profile(username,profilepic); pm = PMF.get().getPersistenceManager(); pm.currentTransaction().begin(); pm.makePersistent(profile); pm.currentTransaction().commit(); resp.getWriter().write("Data stored successfully"); } </code></pre> <p>Server side sending the image</p> <pre><code>String username = req.getParameter("username"); pm = PMF.get().getPersistenceManager(); pm.currentTransaction().begin(); javax.jdo.Query query = pm.newQuery(Profile.class); Collection&lt;Profile&gt; result = (Collection&lt;Profile&gt;) query.execute(); for (Profile result1 : result) { if(result1.getUsername().equalsIgnoreCase(username)) { resp.getWriter().write(result1.getImage().toString()); pm.currentTransaction().commit(); break; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload