title: get Json from URL
body: <p>my app always disconnects at this line (BufferedReader in =new BufferedReader(new InputStreamReader(url.openStream()));) . I want to read from an url the JSON-Data and add this then in my list. Whats wrong in this code pls help me :)</p>
  
  <pre><code>import android.content.Context;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Build;
  import android.os.Bundle;
  import android.app.Activity;
  import android.os.StrictMode;
  import android.view.Menu;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import org.json.JSONArray;
  import org.json.JSONException;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.HashMap;
  
  public class MainActivity extends Activity {
      final ArrayList names =new ArrayList();
      final ArrayList&lt;City&gt; cities = new ArrayList&lt;City&gt;();
  
      String urlMain= "http://************";
  
      //JSON names
  private static final String TAG_CITIES="cities";
  private static final String TAG_NAME="nameDe";
  private static final String TAG_LNG="location_lng";
  private static final String TAG_LAT="location_lat";
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          final ListView list=(ListView) findViewById(R.id.listViewMain);
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, this.names);
          list.setAdapter(adapter);
  
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; citiesList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          //get JSON
  
          try{
              URL url= new URL(urlMain);
              BufferedReader in =new BufferedReader(new InputStreamReader(url.openStream()));
              String str;
              String content="";
              while ((str = in.readLine()) !=null){
                  content+=str;
              }
              in.close();
              JSONArray ja=new JSONArray(content);
              for (int i=0; i &lt;ja.length();i++){
                  String nameDe=ja.getJSONObject(i).getString("nameDe");
                  Double lat=ja.getJSONObject(i).getDouble("location_lat");
                  Double lng=ja.getJSONObject(i).getDouble("location_lng");
                  cities.add(new City(nameDe,lat,lng));
              }
          } catch (MalformedURLException e) {
              e.printStackTrace();
          }catch (IOException e) {
              e.printStackTrace();
          }catch (JSONException e) {
              e.printStackTrace();
          }
          this.locationUpdate();
      }
  
      protected void locationUpdate() {
          LocationListener listener = new MyLocationListener();
          final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
          manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 50, listener);
          Location location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          final ListView list = (ListView) findViewById(R.id.listViewMain);
          for (int i = 0;i&lt;cities.size();i++){
              float[] results= new float[3];
              Location.distanceBetween(location.getLatitude(),location.getLongitude(),cities.get(i).getLat(),cities.get(i).getLng(),results);
              cities.get(i).setDistance(results[0]);
          }
          java.util.Collections.sort(cities);
          this.names.clear();
          for (City city : cities){
              this.names.add(city.getName());
          }
          list.refreshDrawableState();
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>