ln image uploading through http post in php server in android get the Error in http connection java.lang.NullPointerException <p>Hi I m try to upload the image in server through different method in android but it error in logcat Error in http connection java.lang.NullPointerException</p> <p>and here is my code plz tell me where is my mistake in this code for image uploading </p> <pre><code> BitmapFactory.Options options = new BitmapFactory.Options(); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = true; // image path `String` where your image is located BitmapFactory.decodeFile(selectedPath1, options); int bitmapWidth = 400; int bitmapHeight = 250; final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height &gt; bitmapHeight || width &gt; bitmapWidth) { if (width &gt; height) { inSampleSize = Math.round((float) height / (float) bitmapHeight); } else { inSampleSize = Math.round((float) width / (float) bitmapWidth); } } options.inJustDecodeBounds = false; options.inSampleSize = inSampleSize; Bitmap bmpScale = BitmapFactory.decodeFile(selectedPath1, options); ByteArrayOutputStream bos = new ByteArrayOutputStream(); // CompressFormat set up to JPG, you can change to PNG or // whatever you // want; bmpScale.compress(CompressFormat.JPEG, 100, bos); bmpScale.compress(CompressFormat.JPEG, 100, bos); byte[] data = bos.toByteArray(); MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE); // entity.addPart("avatar", new ByteArrayBody(data,mSignMessg + // "-" + new Random().nextInt(1000) + ".jpg")); entity.addPart("image", new ByteArrayBody(data, "pic.jpg")); // add your other name value pairs in entity. ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs .add(new BasicNameValuePair("user_id", mSignMessg)); nameValuePairs.add(new BasicNameValuePair("name", mname .getText().toString())); nameValuePairs.add(new BasicNameValuePair("dob", mbirthday .getText().toString())); nameValuePairs.add(new BasicNameValuePair("bio", mbio.getText() .toString())); nameValuePairs.add(new BasicNameValuePair("sex", mSexValue)); nameValuePairs .add(new BasicNameValuePair("profile_status", "0")); nameValuePairs.add(new BasicNameValuePair("location", mlocation .getText().toString())); // nameValuePairs.add(new BasicNameValuePair("image", ba1)); Log.d("userfile", "userfile " + ba1); // nameValuePairs.add(new BasicNameValuePair("image”, ba1)); for (int i = 0; i &lt; nameValuePairs.size(); i++) { try { entity.addPart( nameValuePairs.get(i).getName(), new StringBody(nameValuePairs.get(i).getValue())); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block Log.d("respons", "image respons " + e); e.printStackTrace(); } } // httppost.setEntity(entity); // // HttpResponse response = httpClient.execute(httppost); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://iapptechnologies.com/snapic/profileXml.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httppost.setEntity(entity); Log.d("nameValuePairs", "nameValuePairs " + nameValuePairs); HttpResponse response = httpclient.execute(httppost); HttpEntity entity1 = response.getEntity(); // print responce outPut = EntityUtils.toString(response.getEntity()); Log.i("GET RESPONSE—-", outPut); Log.d("GET RESPONSE—-", outPut); // is = entity.getContent(); Log.e("log_tag ******", "good connection"); System.out.println("gudconection"); Log.d("god connection ", "gud connection "); bitmapOrg.recycle(); } catch (Exception e) { Log.e("logCatch block***", "Error in http connection " + e.toString()); Log.d("log_catch block ******", "Error in http connection " + e.toString()); } </code></pre> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>*</strong><em>LogCat</em><strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em></strong> </p> <pre><code>12-25 13:05:21.361: D/dalvikvm(390): GC_FOR_MALLOC freed 9503 objects / 583600 bytes in 94ms 12-25 13:05:30.901: D/setpath(390): setpath /mnt/sdcard/Picture/ Poonam.jpg 12-25 13:05:30.911: D/setpath(390): setpath /mnt/sdcard/Picture/ Poonam.jpg 12-25 13:05:30.911: I/System.out(390): selectedPath1 : /mnt/sdcard/Picture/ Poonam.jpg 12-25 13:05:37.130: D/image_name(390): image_name null 12-25 13:05:38.060: D/dalvikvm(390): GC_EXTERNAL_ALLOC freed 3329 objects / 235376 bytes in 636ms 12-25 13:06:06.541: D/GET RESPONSE—-(390): &lt;?xml version="1.0"?&gt; 12-25 13:06:06.541: D/GET RESPONSE—-(390): &lt;Result&gt; 12-25 13:06:06.541: D/GET RESPONSE—-(390): &lt;Transaction&gt;snapic/profileXml&lt;/Transaction&gt; 12-25 13:06:06.541: D/GET RESPONSE—-(390): &lt;Success&gt;True&lt;/Success&gt; 12-25 13:06:06.541: D/GET RESPONSE—-(390): &lt;Message&gt;Profile successfully updated&lt;/Message&gt; 12-25 13:06:06.541: D/GET RESPONSE—-(390): &lt;/Result&gt; 1 12-25 13:06:06.551: E/logCatch block***(390): Error in http connection java.lang.NullPointerException 12-25 13:06:06.551: D/log_catch block ******(390): Error in http connection java.lang.NullPointerException </code></pre>