title: Google Places API on Android: No route to host
body: <p>I am using google places api in my application to show nearby food locations.</p>
  
  <p>I'm using the following code:</p>
  
  <pre><code>public class Background extends AsyncTask&lt;String, Integer, String&gt; {
  
      @Override
      protected void onPostExecute(String result) {
          super.onPostExecute(result);
      }
  
      @Override
      protected String doInBackground(String... params) {
          pfr = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
          lctn = "location=" + latitude + "," + longitude;
          key = "&amp;key=my key";
          type = "&amp;types=" + pfr.getString("type", "food");
          radius = "&amp;radius=" + pfr.getString("radius", "500");
          sensor = "&amp;sensor=false";
          StringBuilder requesturl = new StringBuilder(googlegives);
          requesturl.append(lctn);
          requesturl.append(radius);
          requesturl.append(type);
          requesturl.append(key);
          requesturl.append(sensor);
          DefaultHttpClient client = new DefaultHttpClient();
          HttpGet req = new HttpGet(requesturl.toString());
          Log.d("create", "0");
          try {
              HttpResponse res = client.execute(req);
              HttpEntity jsonentity = res.getEntity();
              String data = EntityUtils.toString(jsonentity);
              JSONObject jsonobj = new JSONObject(data);
              JSONArray resarray = jsonobj.getJSONArray("results");
              if (resarray.length() == 0) {
                  Toast.makeText(getApplicationContext(), "nothing found",
                      Toast.LENGTH_LONG).show();
              } else {
                  int len = resarray.length();
                  for (int j = 0; j &lt; len; j++) {
                      lon = resarray.getJSONObject(j).getJSONObject("geometry")
                              .getJSONObject("location").getDouble("lng");
                      lat = resarray.getJSONObject(j).getJSONObject("geometry")
                              .getJSONObject("location").getDouble("lat");
                      LatLng latLng = new LatLng(lat, lon);
                      googleMap.addMarker(new MarkerOptions()
                              .position(latLng)
                              .title(
                                  resarray.getJSONObject(j).getJSONObject("name")
                                          .toString())
                              .snippet(
                                  resarray.getJSONObject(j)
                                          .getJSONObject("formatted_address")
                                          .toString()));
                  }
              }
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (JSONException e) {
              e.printStackTrace();
          }
          return null;
      }
  }
  </code></pre>
  
  <p>getting latitude and longitude as global variable for getting the user's current location, on running this application on my phone following appear in log cat</p>
  
  <pre><code>03-03 16:52:37.859: W/System.err(4780): java.net.SocketException: No route to host
  03-03 16:52:37.906: W/System.err(4780):     at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
  03-03 16:52:37.906: W/System.err(4780):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
  03-03 16:52:37.906: W/System.err(4780):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
  03-03 16:52:37.914: W/System.err(4780):     at java.net.Socket.connect(Socket.java:1002)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  03-03 16:52:37.914: W/System.err(4780):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  03-03 16:52:37.921: W/System.err(4780):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  03-03 16:52:37.921: W/System.err(4780):     at com.abhishekbietcs.locomap.Mapme$Background.doInBackground(Mapme.java:258)
  03-03 16:52:37.921: W/System.err(4780):     at com.abhishekbietcs.locomap.Mapme$Background.doInBackground(Mapme.java:1)
  03-03 16:52:37.921: W/System.err(4780):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
  03-03 16:52:37.921: W/System.err(4780):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  03-03 16:52:37.921: W/System.err(4780):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  03-03 16:52:37.921: W/System.err(4780):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  03-03 16:52:37.921: W/System.err(4780):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  03-03 16:52:37.921: W/System.err(4780):     at java.lang.Thread.run(Thread.java:1019)
  </code></pre>
  
  <p>Why is this exception being thrown? How can I get rid of it?</p>