title: JSON Trouble cannot convert to JSONArray
body: <p>I know that there are many answers about JSON Arrays but in this case the difference is I found an Android example using JSON when I run it works perfectly, it has 3 classes. Each of them makes a PHP request to a website, which returns a JSON, then the program parses it and makes a list view, my problem is when I run the program it works well using the URLs that came with the default project. But when I use the same PHP code in another server for my own project it returns nothing and log cat says that it cannot be converted to JSONArray</p>
  
  <p>This is the code that works fine:</p>
  
  <pre><code>package com.example.androidhive;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  import org.apache.http.NameValuePair;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.ListActivity;
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  
  import com.example.androidhive.helper.AlertDialogManager;
  import com.example.androidhive.helper.ConnectionDetector;
  import com.example.androidhive.helper.JSONParser;
  
  public class AlbumsActivity extends ListActivity {
  // Connection detector
  ConnectionDetector cd;
  
  // Alert dialog manager
  AlertDialogManager alert = new AlertDialogManager();
  
  // Progress Dialog
  private ProgressDialog pDialog;
  
  // Creating JSON Parser object
  JSONParser jsonParser = new JSONParser();
  
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; albumsList;
  
  // albums JSONArray
  JSONArray albums = null;
  
  // albums JSON url
  private static final String URL_ALBUMS = " http://api.androidhive.info/songs/albums.php";
  
  // ALL JSON node names
  private static final String TAG_ID = "id";
  private static final String TAG_NAME = "name";
  private static final String TAG_SONGS_COUNT = "songs_count";
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_albums);
  
      cd = new ConnectionDetector(getApplicationContext());
  
      // Check for internet connection
      if (!cd.isConnectingToInternet()) {
          // Internet Connection is not present
          alert.showAlertDialog(AlbumsActivity.this, "Internet Connection Error",
                  "Para poder estar actualizado con los eventos por favor, conéctese a Internet.", false);
          // stop executing code by return
          return;
      }
  
      // Hashmap for ListView
      albumsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      // Loading Albums JSON in Background Thread
      new LoadAlbums().execute();
  
      // get listview
      ListView lv = getListView();
  
      /**
       * Listview item click listener
       * TrackListActivity will be lauched by passing album id
       * */
      lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View view, int arg2,
                  long arg3) {
              // on selecting a single album
              // TrackListActivity will be launched to show tracks inside the album
              Intent i = new Intent(getApplicationContext(), TrackListActivity.class);
  
              // send album id to tracklist activity to get list of songs under that album
              String album_id = ((TextView)       view.findViewById(R.id.album_id)).getText().toString();
              i.putExtra("album_id", album_id);               
  
              startActivity(i);
          }
      });     
  }
  
  /**
   * Background Async Task to Load all Albums by making http request
   * */
  class LoadAlbums extends AsyncTask&lt;String, String, String&gt; {
  
      /**
       * Before starting background thread Show Progress Dialog
       * */
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(AlbumsActivity.this);
          pDialog.setMessage("Adquiriendo días. ...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(false);
          pDialog.show();
      }
  
      /**
       * getting Albums JSON
       * */
      protected String doInBackground(String... args) {
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
  
          // getting JSON string from URL
          String json = jsonParser.makeHttpRequest(URL_ALBUMS, "GET",
                  params);
  
          // Check your log cat for JSON reponse
          Log.d("Albums JSON: ", "&gt; " + json);
  
          try {               
              albums = new JSONArray(json);
  
              if (albums != null) {
                  // looping through All albums
                  for (int i = 0; i &lt; albums.length(); i++) {
                      JSONObject c = albums.getJSONObject(i);
  
                      // Storing each json item values in variable
                      String id = c.getString(TAG_ID);
                      String name = c.getString(TAG_NAME);
                      String songs_count = c.getString(TAG_SONGS_COUNT);
  
                      // creating new HashMap
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                      // adding each child node to HashMap key =&gt; value
                      map.put(TAG_ID, id);
                      map.put(TAG_NAME, name);
                      map.put(TAG_SONGS_COUNT, songs_count);
  
                      // adding HashList to ArrayList
                      albumsList.add(map);
                  }
              }else{
                  Log.d("Albums: ", "null");
              }
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return null;
      }
  
      /**
       * After completing background task Dismiss the progress dialog
       * **/
      protected void onPostExecute(String file_url) {
          // dismiss the dialog after getting all albums
          pDialog.dismiss();
          // updating UI from Background Thread
          runOnUiThread(new Runnable() {
              public void run() {
                  /**
                   * Updating parsed JSON data into ListView
                   * */
                  ListAdapter adapter = new SimpleAdapter(
                          AlbumsActivity.this, albumsList,
                          R.layout.list_item_albums, new String[] { TAG_ID,
                                  TAG_NAME, TAG_SONGS_COUNT }, new int[] {
                                  R.id.album_id, R.id.album_name, R.id.songs_count });
  
                  // updating listview
                  setListAdapter(adapter);
              }
          });
  
      }
  
  }
  }
  </code></pre>
  
  <p>You will notice at the begining of the code it says  </p>
  
  <pre><code>private static final String URL_ALBUMS = "http://api.androidhive.info/songs/albums.php"
  </code></pre>
  
  <p>that is the URL I want to change for my own code.</p>
  
  <p>There are 2 PHP files, albums.php and data.php which stores all the information.</p>
  
  <p>albums.php</p>
  
  <pre><code>&lt;?php
  
  
  
  include_once './data.php';
  $albums = array();
  
  // looping through each album
  foreach ($album_tracks as $album) {
  $tmp = array();
  $tmp["id"] = $album["id"];
  $tmp["name"] = $album["album"];
  $tmp["songs_count"] = count($album["songs"]);
  
  // push album
  array_push($albums, $tmp);
  }
  
  // printing json
  echo json_encode($albums);
  ?&gt;
  </code></pre>
  
  <p>and data.php</p>
  
  <pre><code>&lt;?php
  
  
  $album_tracks = array(
  1 =&gt; array(
      "id" =&gt; 1,
      "album" =&gt; "127 Hours",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "Never Hear Surf Music Again", "duration" =&gt; "5:52"),
          array("id" =&gt; 2, "name" =&gt; "The Canyon", "duration" =&gt; "3:01"),
          array("id" =&gt; 3, "name" =&gt; "Liberation Begins", "duration" =&gt; "2:14"),
          array("id" =&gt; 4, "name" =&gt; "Touch of the Sun", "duration" =&gt; "4:39"),
          array("id" =&gt; 5, "name" =&gt; "Lovely Day", "duration" =&gt; "4:16"),
          array("id" =&gt; 6, "name" =&gt; "Ca Plane Pour Moi", "duration" =&gt; "3:00"),
          array("id" =&gt; 7, "name" =&gt; "Liberation In A Dream", "duration" =&gt; "4:06"),
          array("id" =&gt; 8, "name" =&gt; "If You Love Me (Really Love Me)", "duration" =&gt; "3:27"),
          array("id" =&gt; 9, "name" =&gt; "Acid Darbari", "duration" =&gt; "4:21"),
          array("id" =&gt; 10, "name" =&gt; "R.I.P.", "duration" =&gt; "5:11"),
          array("id" =&gt; 11, "name" =&gt; "Festival", "duration" =&gt; "9:26"),
          array("id" =&gt; 12, "name" =&gt; "If I Rise", "duration" =&gt; "4:38"),
          array("id" =&gt; 13, "name" =&gt; "Liberation", "duration" =&gt; "3:11"),
          array("id" =&gt; 14, "name" =&gt; "Nocturne No. 2 in E flat", "duration" =&gt; "4:01")
      )
  ),
  2 =&gt; array(
      "id" =&gt; 2,
      "album" =&gt; "Adele 21",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "Rolling In The Deep", "duration" =&gt; "03:48"),
          array("id" =&gt; 2, "name" =&gt; "Rumour Has It", "duration" =&gt; "03:43"),
          array("id" =&gt; 3, "name" =&gt; "Turning Tables", "duration" =&gt; "04:10"),
          array("id" =&gt; 4, "name" =&gt; "Don’t You Remember", "duration" =&gt; "04:03"),
          array("id" =&gt; 5, "name" =&gt; "Set Fire To The Rain", "duration" =&gt; "04:02"),
          array("id" =&gt; 6, "name" =&gt; "He Won’t Go", "duration" =&gt; "04:38"),
          array("id" =&gt; 7, "name" =&gt; "Take It All", "duration" =&gt; "03:48"),
          array("id" =&gt; 8, "name" =&gt; "I’ll Be Waiting", "duration" =&gt; "04:01"),
          array("id" =&gt; 9, "name" =&gt; "One And Only", "duration" =&gt; "05:48"),
          array("id" =&gt; 10, "name" =&gt; "Lovesong", "duration" =&gt; "05:16"),
          array("id" =&gt; 11, "name" =&gt; "Someone Like You", "duration" =&gt; "04:45")
      )
  ),
  3 =&gt; array(
      "id" =&gt; 3,
      "album" =&gt; "Lana Del Rey - Born to Die",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "Born to Die", "duration" =&gt; "4:46"),
          array("id" =&gt; 2, "name" =&gt; "Off to the Races", "duration" =&gt; "5:00"),
          array("id" =&gt; 3, "name" =&gt; "Blue Jeans", "duration" =&gt; "3:29"),
          array("id" =&gt; 4, "name" =&gt; "Video Games", "duration" =&gt; "4:42"),
          array("id" =&gt; 5, "name" =&gt; "Diet Mountain Dew", "duration" =&gt; "3:43"),
          array("id" =&gt; 6, "name" =&gt; "National Anthem", "duration" =&gt; "3:51"),
          array("id" =&gt; 7, "name" =&gt; "Dark Paradise", "duration" =&gt; "4:03"),
          array("id" =&gt; 8, "name" =&gt; "Radio", "duration" =&gt; "3:35"),
          array("id" =&gt; 9, "name" =&gt; "Carmen", "duration" =&gt; "4:09"),
          array("id" =&gt; 10, "name" =&gt; "Million Dollar Man", "duration" =&gt; "3:50"),
          array("id" =&gt; 11, "name" =&gt; "Summertime Sadness", "duration" =&gt; "4:25"),
          array("id" =&gt; 12, "name" =&gt; "This Is What Makes Us Girls", "duration" =&gt; "4:00")
      )
  ),
  4 =&gt; array(
      "id" =&gt; 4,
      "album" =&gt; "Once",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "Falling Slowly", "duration" =&gt; "4:05"),
          array("id" =&gt; 2, "name" =&gt; "If You Want Me", "duration" =&gt; "3:47"),
          array("id" =&gt; 3, "name" =&gt; "Broken Hearted Hoover Fixer Sucker Guy", "duration" =&gt; "0:52"),
          array("id" =&gt; 4, "name" =&gt; "When Your Mind's Made Up", "duration" =&gt; "3:42"),
          array("id" =&gt; 5, "name" =&gt; "Lies", "duration" =&gt; "3:58"),
          array("id" =&gt; 6, "name" =&gt; "Gold", "duration" =&gt; "3:59"),
          array("id" =&gt; 7, "name" =&gt; "The Hill", "duration" =&gt; "4:34"),
          array("id" =&gt; 8, "name" =&gt; "Fallen From The Sky", "duration" =&gt; "3:24"),
          array("id" =&gt; 9, "name" =&gt; "Leave", "duration" =&gt; "2:46"),
          array("id" =&gt; 10, "name" =&gt; "Trying To Pull Myself Away", "duration" =&gt; "3:35"),
          array("id" =&gt; 11, "name" =&gt; "All The Way Down", "duration" =&gt; "2:38"),
          array("id" =&gt; 12, "name" =&gt; "Once", "duration" =&gt; "3:37"),
          array("id" =&gt; 13, "name" =&gt; "Say It To Me Now", "duration" =&gt; "2:36")
      )
  ),
  5 =&gt; array(
      "id" =&gt; 5,
      "album" =&gt; "Away We Go",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "All My Days", "duration" =&gt; "4:56"),
          array("id" =&gt; 2, "name" =&gt; "Blue Mind", "duration" =&gt; "5:42"),
          array("id" =&gt; 3, "name" =&gt; "What Is Life", "duration" =&gt; "4:24"),
          array("id" =&gt; 4, "name" =&gt; "Song For You", "duration" =&gt; "4:37"),
          array("id" =&gt; 5, "name" =&gt; "Golden Brown", "duration" =&gt; "3:31"),
          array("id" =&gt; 6, "name" =&gt; "Towards The Sun", "duration" =&gt; "4:40"),
          array("id" =&gt; 7, "name" =&gt; "Meet Me In The Morning", "duration" =&gt; "4:22"),
          array("id" =&gt; 8, "name" =&gt; "Breathe", "duration" =&gt; "4:16"),
          array("id" =&gt; 9, "name" =&gt; "Wait", "duration" =&gt; "5:55"),
          array("id" =&gt; 10, "name" =&gt; "The Ragged Sea", "duration" =&gt; "3:20"),
          array("id" =&gt; 11, "name" =&gt; "Oh! Sweet Nuthin'", "duration" =&gt; "7:29"),
          array("id" =&gt; 12, "name" =&gt; "Orange Sky", "duration" =&gt; "6:09"),
          array("id" =&gt; 13, "name" =&gt; "Crinan Wood", "duration" =&gt; "5:45")
      )
  ),
  6 =&gt; array(
      "id" =&gt; 6,
      "album" =&gt; "Eminem Curtain Call",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "My Name Is", "duration" =&gt; "4:28"),
          array("id" =&gt; 2, "name" =&gt; "The Way I Am", "duration" =&gt; "4:51"),
          array("id" =&gt; 3, "name" =&gt; "Lose Yourself", "duration" =&gt; "5:21"),
          array("id" =&gt; 4, "name" =&gt; "Shake That", "duration" =&gt; "4:34"),
          array("id" =&gt; 5, "name" =&gt; "Sing For The Moment", "duration" =&gt; "5:40"),
          array("id" =&gt; 6, "name" =&gt; "Without Me", "duration" =&gt; "4:47"),
          array("id" =&gt; 7, "name" =&gt; "Like Toy Soldiers", "duration" =&gt; "4:51"),
          array("id" =&gt; 8, "name" =&gt; "The Real Slim Shady", "duration" =&gt; "4:44"),
          array("id" =&gt; 9, "name" =&gt; "Mockingbird", "duration" =&gt; "4:11"),
          array("id" =&gt; 10, "name" =&gt; "Guilty Conscience", "duration" =&gt; "3:19"),
          array("id" =&gt; 11, "name" =&gt; "Cleanin' Out My Closet", "duration" =&gt; "4:58"),
          array("id" =&gt; 12, "name" =&gt; "Just Lose It", "duration" =&gt; "4:08"),
          array("id" =&gt; 13, "name" =&gt; "When I'm Gone", "duration" =&gt; "4:40"),
          array("id" =&gt; 14, "name" =&gt; "Stan", "duration" =&gt; "6:21")
      )
  ),
  7 =&gt; array(
      "id" =&gt; 7,
      "album" =&gt; "Bad Meets Evil Eminem",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "Lighters", "duration" =&gt; "5:21"),
          array("id" =&gt; 2, "name" =&gt; "Fast Lane", "duration" =&gt; "3:19"),
          array("id" =&gt; 3, "name" =&gt; "Above the Law", "duration" =&gt; "6:21"),
          array("id" =&gt; 4, "name" =&gt; "Welcome 2 Hell", "duration" =&gt; "4:34"),
          array("id" =&gt; 5, "name" =&gt; "Take from Me", "duration" =&gt; "4:51"),
          array("id" =&gt; 6, "name" =&gt; "The Reunion", "duration" =&gt; "4:44"),
          array("id" =&gt; 7, "name" =&gt; "A Kiss", "duration" =&gt; "3:19"),
          array("id" =&gt; 8, "name" =&gt; "Echo", "duration" =&gt; "6:21"),
          array("id" =&gt; 9, "name" =&gt; "Lighters", "duration" =&gt; "4:40"),
          array("id" =&gt; 10, "name" =&gt; "Living Proof", "duration" =&gt; "3:49"),
          array("id" =&gt; 11, "name" =&gt; "Loud Noises", "duration" =&gt; "3:19")
      )
  ),
  8 =&gt; array(
      "id" =&gt; 8,
      "album" =&gt; "Safe Trip Home",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "Don't Believe in Love", "duration" =&gt; "3:52"),
          array("id" =&gt; 2, "name" =&gt; "Quiet Times", "duration" =&gt; "3:16"),
          array("id" =&gt; 3, "name" =&gt; "Never Want to Say It's Love", "duration" =&gt; "3:34"),
          array("id" =&gt; 4, "name" =&gt; "Grafton Street", "duration" =&gt; "5:56"),
          array("id" =&gt; 5, "name" =&gt; "It Comes And It Goes", "duration" =&gt; "3:26"),
          array("id" =&gt; 6, "name" =&gt; "Look No Further", "duration" =&gt; "3:15"),
          array("id" =&gt; 7, "name" =&gt; "Us 2 Little Gods", "duration" =&gt; "4:48"),
          array("id" =&gt; 8, "name" =&gt; "The Day Before The Day", "duration" =&gt; "4:12"),
          array("id" =&gt; 9, "name" =&gt; "Let's Do the Things We Normally Do", "duration" =&gt; "4:08"),
          array("id" =&gt; 10, "name" =&gt; "Burnin Love", "duration" =&gt; "4:10"),
          array("id" =&gt; 11, "name" =&gt; "Northern Skies", "duration" =&gt; "8:53")
      )
  ),
  9 =&gt; array(
      "id" =&gt; 9,
      "album" =&gt; "No Angel",
      "songs" =&gt; array(
          array("id" =&gt; 1, "name" =&gt; "Here With Me", "duration" =&gt; "4:05"),
          array("id" =&gt; 2, "name" =&gt; "Hunter", "duration" =&gt; "3:55"),
          array("id" =&gt; 3, "name" =&gt; "Don't Think Of Me", "duration" =&gt; "4:32"),
          array("id" =&gt; 4, "name" =&gt; "My Lover's Gone", "duration" =&gt; "4:27"),
          array("id" =&gt; 5, "name" =&gt; "All You Want", "duration" =&gt; "3:53"),
          array("id" =&gt; 6, "name" =&gt; "Thank You", "duration" =&gt; "3:36"),
          array("id" =&gt; 7, "name" =&gt; "Honestly Ok", "duration" =&gt; "4:37"),
          array("id" =&gt; 8, "name" =&gt; "Slide", "duration" =&gt; "4:50"),
          array("id" =&gt; 9, "name" =&gt; "Isobel", "duration" =&gt; "3:55"),
          array("id" =&gt; 10, "name" =&gt; "I'm No Angel", "duration" =&gt; "3:55"),
          array("id" =&gt; 11, "name" =&gt; "My Life", "duration" =&gt; "2:59"),
          array("id" =&gt; 12, "name" =&gt; "Take My Hand", "duration" =&gt; "6:50")
      )
      )
  );
  ?&gt;
  </code></pre>
  
  <p>Well I stored the PHP files in a dropbox public folder and tried to change the first url api.androidhive.../songs/albums.php</p>
  
  <p>For the new one where PHP is stored in dropbox<br>
  "<a href="https://dl.dropboxusercontent.com/u/105156121/albums.php" rel="nofollow noreferrer">https://dl.dropboxusercontent.com/u/105156121/albums.php</a>"  </p>
  
  <p>But when I changed the server where it is allocated it only returns me blank.</p>