title: program crashing at .connect() on Android, not connecting
body: <p>I been trying to figure this out for hours now. I've searched for answers, but I can't find an answer. I have never bothered to ask before and this is the first time I'm asking a question. Basically what I am doing is breaking up  my coding for organization purposes. The following snippet works just fine, but when I take it and place it into another class the urlConnect(); connects just fine. I've marked it below.</p>
  
  <pre><code>public String downloadUrl(String strUrl) throws IOException{
      String data = "";
      InputStream iStream = null;
      HttpURLConnection urlConnection = null;
  
      try{
          URL url = new URL(strUrl);
          String line = "";
  
          // Creating an http connection to communicate with url 
          urlConnection = (HttpURLConnection) url.openConnection();
  
          /* Connecting to url */
          urlConnection.connect(); &lt;-------------------------works in this snippet
  
          /* Reading data from url */
          iStream = urlConnection.getInputStream();
          BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
          StringBuffer sb  = new StringBuffer();
  
          while((line = br.readLine()) != null){
              sb.append(line);
          }
          data = sb.toString();
          br.close();
      }
      catch(Exception e){
          Log.d("Exception while downloading url", e.toString());
      }
      finally {
          iStream.close();
          urlConnection.disconnect();
      }
      return data;
  }
  </code></pre>
  
  <p>So this following snippet, is pretty much identical. But for some reason it doesn't want to connect:</p>
  
  <pre><code>public String getJSONobject(String strUrl) throws IOException{
      String data = "";
      InputStream iStream = null;
      HttpURLConnection urlConnection = null;
  
      try{
          URL url = new URL(strUrl);
          String line = "";
          urlConnection = (HttpURLConnection) url.openConnection();
          urlConnection.connect();    &lt;------------------ Does not work
  
          iStream = urlConnection.getInputStream();
          BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
          StringBuffer sb  = new StringBuffer();
  
          while((line = br.readLine()) != null){
              sb.append(line);
          }
          data = sb.toString();
          br.close();
          iStream.close();    
      }               
      catch (MalformedURLException e1) {
          e1.printStackTrace();
      } 
      catch (IOException e1) {
          e1.printStackTrace();
      } 
      finally {
          if(null != urlConnection) { urlConnection.disconnect(); 
      }
      return data;
  </code></pre>
  
  <p>The LogCat:</p>
  
  <pre><code>&gt;at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1131)
  &gt;at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
  &gt;at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
  &gt;at java.net.InetAddress.getAllByName(InetAddress.java:214)
  &gt;at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:70)
  &gt;at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:50)
  &gt;at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
  &gt;at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
  &gt;at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
  &gt;at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
  &gt;at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
  &gt;at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
  &gt;at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
  &gt;at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
  &gt;at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
  &gt;at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
  &gt;at com.navsquad.shsu.katlas2.RouteJSONobject.getJSONobject(RouteJSONobject.java:57)
  &gt;at com.navsquad.shsu.katlas2.CreateRoute.create(CreateRoute.java:41)
  &gt;at com.navsquad.shsu.katlas2.MainActivity$3.onMapClick(MainActivity.java:84)
  &gt;at com.google.android.gms.maps.GoogleMap$6.onMapClick(Unknown Source)
  &gt;at com.google.android.gms.internal.t$a.onTransact(Unknown Source)
  &gt;at android.os.Binder.transact(Binder.java:326)
  &gt;at com.google.android.gms.maps.internal.IOnMapClickListener$Stub$Proxy.onMapClick(IOnMapClickListener.java:93)
  &gt;at maps.i.s.b(Unknown Source)
  &gt;at maps.y.v.c(Unknown Source)
  &gt;at maps.y.bf.onSingleTapConfirmed(Unknown Source)
  &gt;at maps.d.v.onSingleTapConfirmed(Unknown Source)
  &gt;at maps.d.j.handleMessage(Unknown Source)
  &gt;at android.os.Handler.dispatchMessage(Handler.java:99)
  &gt;at android.os.Looper.loop(Looper.java:137)
  &gt;at android.app.ActivityThread.main(ActivityThread.java:5059)
  &gt;at java.lang.reflect.Method.invokeNative(Native Method)
  &gt;at java.lang.reflect.Method.invoke(Method.java:511)
  &gt;at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
  &gt;at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
  &gt;at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>So again to make it clear, all I was doing was making a separate class for my own organization. Originally I had a parser included in, but I have now split it up into different classes, so I can use other parsers with the string/JSON Object. If you could help me figure out what is different from before, I would appreciate. Original class was in an implemented AsyncTask Class.</p>