title: how to get JSONArray from http Url and how to set JSONArray to spinner in android?
body: <p>I have JSONArray ["category_1","category_2","category_3"] and I don't get data.
  And how I set this data to spinner or listview in Android.  </p>
  
  <p>E:</p>
  
  <p>where are faults?</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      String urlCat = "http://tvapp.pcrevue.sk/categories.json";
  
      Spinner spinner;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          try {
              JSONArray jsonArray;
              jsonArray = getJSONArrayFromUrl(urlCat);
  
              final String[] array_spinner = new String[jsonArray.length()];
  
              //int show_total = jsonArray.length();
  
              //Toast.makeText(flash_tattoo.this, show_total + "test", Toast.LENGTH_LONG).show();
  
              for (int i=0; i&lt;jsonArray.length(); i++)
              {
                  String styleValue = jsonArray.getJSONArray(0).getString(i);
                  array_spinner[i] = styleValue;
  
              }
              ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt; (this, android.R.layout.simple_spinner_item,array_spinner);
  
              adapter.setDropDownViewResource(R.layout.activity_main);
              spinner.setAdapter(adapter);
  
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
  
      }
  
      public JSONArray getJSONArrayFromUrl(String url) {
          InputStream is = null;
          JSONArray jObj = null;
          String json = "";
          // Making HTTP request
          try {
              // defaultHttpClient
              DefaultHttpClient httpClient = new DefaultHttpClient();
              HttpGet httpGet = new HttpGet(url);
  
              HttpResponse httpResponse = httpClient.execute(httpGet);
              HttpEntity httpEntity = httpResponse.getEntity();
              is = httpEntity.getContent();
  
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          try {
              BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"));
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  //json += line;
                  sb.append(line + "\n");
              }
              is.close();
              json = sb.toString();
          } catch (Exception e) {
              Log.e("Buffer Error", "Error converting result " + e.toString());
          }
  
          // try parse the string to a JSON object
          try {
              jObj = new JSONArray(json);
          } catch (JSONException e) {
              Log.e("JSON Parser", "Error parsing data " + e.toString());
          }
  
          // return JSON String
          return jObj;
  
      }
  }    
  </code></pre>