title: force close when send data to webserver
body: <p>i try send data to web server.</p>
  
  <p>first. i use only <code>HttpResponse</code> to know the data is sent or not in device and it works </p>
  
  <p>and i try to put <code>ResponseHandler</code> to know the data is sent or not read in webserver.</p>
  
  <p>i create two response.</p>
  
  <p>when the data is not sent or fail,<br>
  both of them, the error message and the toast is show and works</p>
  
  <p>but when the data is sent the toast is show but the error message not show  and then force close</p>
  
  <p>here is my code</p>
  
  <pre><code>private boolean SendDataFoto(CPetakRecord rec){
  
  
          String slon=String.format("%f", rec.dLongitude);
          String slat=String.format("%f", rec.dLatitude);
          String sacc=String.format("%f", rec.dAccuracy);
          String jnsHm=String.format(rec.jenisHm);
          String jmlHm=String.format(rec.jumlahHm);
          String jnsMsh=String.format(rec.jenisMsh);
          String jmlMsh=String.format(rec.jumlahMsh);
          String intens=String.format(rec.intensitas);
          String luasAncam=String.format(rec.luasTerancam);
          String nmPetak=String.format(rec.nmPetak);
          String code=String.format(rec.code);
          String userId=String.format(rec.userId);
          String varietas=String.format(rec.varietas);
          String dbLon=String.format("%f", rec.dbLon);
          String dbLat=String.format("%f", rec.dbLat);
  
  
          File file=new File(rec.sFilename);
          String sfname=file.getName();
          String cfname=file.getName();
          String lfname=rec.sFilename;
          sfname = sfname.substring(0, sfname.lastIndexOf("."));
          Calendar cal=Calendar.getInstance();
          cal.setTime(new Date(rec.lDate));
          String sdat=CUtilities.DateToString(cal);
  
  
          String url;
          String spetak;
          if (CGeneral.nPetakTetap==CGeneral.ACTIVITY_FOR_PETAK){
              url = CGlobalConfig.getURLRcvrPetak();
              spetak="petak";
          }
          else{
              url = CGlobalConfig.getURLRcvrPeliharaImage();
              spetak="pelihara";
          }
  
          Bitmap bmp=BitmapFactory.decodeFile(lfname);
          ByteArrayOutputStream bao = new ByteArrayOutputStream();
  
          bmp.compress(Bitmap.CompressFormat.JPEG, 90, bao);
  
          byte[] ba = bao.toByteArray();
  
          HttpEntity entity=null;
  
          try {
  
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost(url);
              ByteArrayBody bab = new ByteArrayBody(ba, spetak+"_"+cfname);
              MultipartEntity reqEntity = new MultipartEntity(
              HttpMultipartMode.BROWSER_COMPATIBLE);
              reqEntity.addPart("image", bab);
              reqEntity.addPart("category", new StringBody(spetak));
              reqEntity.addPart("foto", new StringBody(spetak+"_"+cfname));//
              reqEntity.addPart("tgl", new StringBody(sdat));//
              reqEntity.addPart("lat_petak", new StringBody(slat));//
              reqEntity.addPart("lon_petak", new StringBody(slon));//
              reqEntity.addPart("accuracy", new StringBody(sacc));
              reqEntity.addPart("jenis_hama", new StringBody(jnsHm));//
              reqEntity.addPart("jumlah_hama", new StringBody(jmlHm));//
              reqEntity.addPart("jenis_musuh", new StringBody(jnsMsh));//
              reqEntity.addPart("jumlah_musuh", new StringBody(jmlMsh));//
              reqEntity.addPart("int_serangan", new StringBody(intens));//
              reqEntity.addPart("luas_terancam", new StringBody(luasAncam));//
              reqEntity.addPart("nama_petak", new StringBody(nmPetak));//
              reqEntity.addPart("code_db", new StringBody(code));//
              reqEntity.addPart("user_id", new StringBody(userId));//
              reqEntity.addPart("varietas", new StringBody(varietas));//
              reqEntity.addPart("lon_db", new StringBody(dbLon));//
              reqEntity.addPart("lat_db", new StringBody(dbLat));//
  
              httppost.setEntity(reqEntity);
              HttpResponse response = httpclient.execute(httppost);
              ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
              String response2 = httpclient.execute(httppost, responseHandler);
              //if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
              final String reverseString = response2;
              runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(UpdateLog.this, "response : " + reverseString, Toast.LENGTH_LONG).show();
                    }
                  });
              entity = response.getEntity();
              //}
  
          }
  
          catch (final ClientProtocolException e) {
              runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(UpdateLog.this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
                    }
                  });
          // TODO Auto-generated catch block
          } catch (final IOException e) {
              runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(UpdateLog.this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
                    }
                  });
          // TODO Auto-generated catch block
          }
          catch (Exception e) {
              Log.e(e.getClass().getName(), e.getMessage());
          }
          String temp = null;
  
          try {
  
              if(entity == null){
                  publishProgress(0,"Send Fail");
                  SystemClock.sleep(500);
                  return false;
              }
              else{
              temp = EntityUtils.toString(entity);
              }
          } catch (ParseException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
  
  
          if (temp.compareTo("SUCCESS") == 0) {
              publishProgress(0,"Send Ok");
              SystemClock.sleep(500);
              return true;
          }
          else{
              publishProgress(0,"Send Fail");
              return false;               
          }   
  
      }
  </code></pre>
  
  <p>and here is my logcat</p>
  
  <pre><code>03-28 00:38:43.421: ERROR/AndroidRuntime(3028): FATAL EXCEPTION: AsyncTask #2
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028): java.lang.RuntimeException: An error occured while executing doInBackground()
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.lang.Thread.run(Thread.java:1019)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028): Caused by: java.lang.NullPointerException
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at hariff.ltis.petaktetap.UpdateLog$MyAsyncTaskPetak.SendDataFoto(UpdateLog.java:961)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at hariff.ltis.petaktetap.UpdateLog$MyAsyncTaskPetak.doInBackground(UpdateLog.java:814)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at hariff.ltis.petaktetap.UpdateLog$MyAsyncTaskPetak.doInBackground(UpdateLog.java:1)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  03-28 00:38:43.421: ERROR/AndroidRuntime(3028):     ... 4 more
  </code></pre>
  
  <p>the error is in line <code>if (temp.compareTo("SUCCESS") == 0) {</code></p>
  
  <p>how to fix that?,  i want the toast and the error message is show together when the data is sent.</p>