title: org.json.JSONException: Value [....] of type org.json.JSONArray cannot be converted to JSONObject
body: <p>Got stuck to this error..:(
  Here is my code..
  json exception cannot be converted to jsonobject..</p>
  
  <p>this is my Furniture.java file. this is the main file that is executed first
  i want to show the layout as listview which shows logo, furniture name and its price.</p>
  
  <pre><code>public class Furniture extends Activity
  {
  TextView login;
  ListView list;
  Button b,search;
  String s,s1="error";
  int value;
  
  
  
   @Override
     public void onCreate(Bundle savedInstanceState) 
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.furniture);
  
      String strUrl = "http://realroom.byethost24.com/realroom/furniture.php"
  
      Log.d("c1 :", s1);
      DownloadTask downloadTask = new DownloadTask();
      downloadTask.execute(strUrl);
      list = (ListView) findViewById(R.id.flist);     
   }
  
   public boolean onCreateOptionsMenu(Menu menu) 
   {
      // TODO Auto-generated method stub
      super.onCreateOptionsMenu(menu);
      MenuInflater blowup = getMenuInflater();
      blowup.inflate(R.menu.menu, menu);
      return true;
   }
  
   @Override
   public boolean onOptionsItemSelected(MenuItem item) 
   {
      // TODO Auto-generated method stub
      Intent i;
      switch(item.getItemId())
      {
          case R.id.checkout:
              i = new Intent(Furniture.this, Payment.class);
              startActivity(i);
              break;
  
          case R.id.aboutUs:
             i = new Intent(Furniture.this,AboutUs.class);
             startActivity(i);
             break;
  
          case R.id.profile:
             i = new Intent(Furniture.this,Profile.class);
             startActivity(i);
             break;
  
          case R.id.help:
             i = new Intent(Furniture.this,Help.class);
             startActivity(i);
             break;
  
      }
      return false;
   }
  
  
   private String downloadUrl(String strUrl) throws IOException
   {
      String data = "";
      InputStream istream = null;
      try
      {
          Log.d("c2",s1);
          URL url = new URL(strUrl);
          HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
          urlConnection.connect();
          istream = urlConnection.getInputStream();
          BufferedReader br = new BufferedReader(new InputStreamReader(istream));
          StringBuffer sb = new StringBuffer();
          String line = "";
          while((line=br.readLine())!=null)
          {
              sb.append(line);
          }
          data = sb.toString();
          br.close();
      }
      catch(Exception e)
      {
          Log.e("c3",s1);
          Log.d("Exception while downloading url", e.toString());
      }
      finally
      {
          istream.close();
      }
      return data;
   }
  
  /** AsyncTask to download json data */
   private class DownloadTask extends AsyncTask&lt;String, Integer, String&gt;
   {
      String data = null;
      @Override
      protected String doInBackground(String... url) 
      {
          try
          {
              data = downloadUrl(url[0]);
              Log.d("c26",s1);
              System.out.print(data);
          }
          catch(Exception e)
          {
              Log.d("Background Task",e.toString());
              Log.e("c6",s1);
          }
          return data;
      }
  
      @Override
      protected void onPostExecute(String result) 
      {
  
          // The parsing of the xml data is done in a non-ui thread
          ListViewLoaderTask listViewLoaderTask = new ListViewLoaderTask();
  
          // Start parsing xml data
          listViewLoaderTask.execute(result);
      }
  }
  
  /** AsyncTask to parse json data and load ListView */
   private class ListViewLoaderTask extends AsyncTask&lt;String, Void, SimpleAdapter&gt;
   {
  
      JSONObject jObject;
      // Doing the parsing of xml data in a non-ui thread
      @Override
      protected SimpleAdapter doInBackground(String... strJson) 
      {
          try
          {
              Log.d("c4",s1);
              jObject = new JSONObject(strJson[0]);
              Log.d("c44",s1);
              FurnitureJsonParser furnitureJsonParser = new FurnitureJsonParser();
              Log.d("c84",s1);
              furnitureJsonParser.parse(jObject);
              Log.d("c94",s1);
          }
          catch(Exception e)
          {
              Log.d("JSON Exception1",e.toString());
              Log.e("c5",s1);
          }
  
          // Instantiating json parser class
          FurnitureJsonParser furnitureJsonParser = new FurnitureJsonParser();
  
          // A list object to store the parsed countries list
          List&lt;HashMap&lt;String, Object&gt;&gt; furnitures = null;
  
          try
          {
              // Getting the parsed data as a List construct
              furnitures = furnitureJsonParser.parse(jObject);
          }
          catch(Exception e)
          {
              Log.d("Exception",e.toString());
              Log.e("c7",s1);
          }
  
          // Keys used in Hashmap
          String[] from = { "furniture","flag","details"};
  
          // Ids of views in listview_layout
          int[] to = { R.id.tv_fur,R.id.iv_icon,R.id.tv_fur_details};
  
          // Instantiating an adapter to store each items
          // R.layout.listview_layout defines the layout of each item
          SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), furnitures, R.layout.f_item, from, to);
  
          return adapter;
      }
  
      /** Invoked by the Android on "doInBackground" is executed */
      @Override
      protected void onPostExecute(SimpleAdapter adapter) {
  
          // Setting adapter for the listview
          list.setAdapter(adapter);
          Log.d("c8",s);
          for(int i=0;i&lt;adapter.getCount();i++)
          {
              HashMap&lt;String, Object&gt; hm = (HashMap&lt;String, Object&gt;) adapter.getItem(i);
              String imgUrl = (String) hm.get("flag_path");
              ImageLoaderTask imageLoaderTask = new ImageLoaderTask();
  
              HashMap&lt;String, Object&gt; hmDownload = new HashMap&lt;String, Object&gt;();
              hm.put("flag_path",imgUrl);
              hm.put("position", i);
              Log.d("c9",s1);
              // Starting ImageLoaderTask to download and populate image in the listview
              imageLoaderTask.execute(hm);
          }
      }
  }
  
  
  /** AsyncTask to download and load an image in ListView */
   private class ImageLoaderTask extends AsyncTask&lt;HashMap&lt;String, Object&gt;, Void, HashMap&lt;String, Object&gt;&gt;{
  
      @Override
      protected HashMap&lt;String, Object&gt; doInBackground(HashMap&lt;String, Object&gt;... hm) {
  
          InputStream iStream=null;
          Log.d("c10",s1);
          String imgUrl = (String) hm[0].get("flag_path");
          int position = (Integer) hm[0].get("position");
          URL url;
          Log.d("c11",s1);
          try 
          {
              url = new URL(imgUrl);
  
              // Creating an http connection to communicate with url
              HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  
              // Connecting to url
              urlConnection.connect();
  
              // Reading data from url
              iStream = urlConnection.getInputStream();
  
              // Getting Caching directory
              File cacheDirectory = getBaseContext().getCacheDir();
  
              Log.d("c12",s1);
              // Temporary file to store the downloaded image
              File tmpFile = new File(cacheDirectory.getPath() + "/wpta_"+position+".jpeg");
  
              Log.d("c13",s1);
              // The FileOutputStream to the temporary file
              FileOutputStream fOutStream = new FileOutputStream(tmpFile);
  
              // Creating a bitmap from the downloaded inputstream
              Bitmap b = BitmapFactory.decodeStream(iStream);
  
              // Writing the bitmap to the temporary file as png file
              b.compress(Bitmap.CompressFormat.JPEG,100, fOutStream);
  
              // Flush the FileOutputStream
              fOutStream.flush();
  
             //Close the FileOutputStream
             fOutStream.close();
  
              // Create a hashmap object to store image path and its position in the listview
              HashMap&lt;String, Object&gt; hmBitmap = new HashMap&lt;String, Object&gt;();
  
              // Storing the path to the temporary image file
              hmBitmap.put("flag",tmpFile.getPath());
  
              // Storing the position of the image in the listview
              hmBitmap.put("position",position);
  
              // Returning the HashMap object containing the image path and position
              return hmBitmap;
  
          }
          catch (Exception e) 
          {
              e.printStackTrace();
              Log.e("c14",s1);
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(HashMap&lt;String, Object&gt; result) 
      {
          Log.d("c15",s1);
          // Getting the path to the downloaded image
          String path = (String) result.get("flag");
  
          // Getting the position of the downloaded image
          int position = (Integer) result.get("position");
  
          // Getting adapter of the listview
          SimpleAdapter adapter = (SimpleAdapter ) list.getAdapter();
  
          // Getting the hashmap object at the specified position of the listview
          HashMap&lt;String, Object&gt; hm = (HashMap&lt;String, Object&gt;) adapter.getItem(position);
  
          // Overwriting the existing path in the adapter
          hm.put("flag",path);
  
          // Noticing listview about the dataset changes
          adapter.notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>FurnitureJsonParser.java file</p>
  
  <p>this file is used to parse the data via JSON</p>
  
  <pre><code>class FurnitureJsonParser 
  {
  String s="error";
  public List&lt;HashMap&lt;String,Object&gt;&gt; parse(JSONObject jObject)
  {
      JSONArray jFurnitures = null;
      try
      {
          jFurnitures = jObject.getJSONArray("furnitures");
      }
      catch(JSONException e)
      {
          e.printStackTrace();
      }
      return getFurnitures(jFurnitures);
  }
  
  private List&lt;HashMap&lt;String, Object&gt;&gt; getFurnitures(JSONArray jFurnitures)
  {
      int furnitureCount = jFurnitures.length();
      List&lt;HashMap&lt;String, Object&gt;&gt; furnitureList = new ArrayList&lt;HashMap&lt;String,Object&gt;&gt;();
      HashMap&lt;String, Object&gt; furniture = null;
  
      for(int i=0; i&lt;furnitureCount;i++)
      {
          try
          {
              furniture = getFurniture((JSONObject)jFurnitures.get(i));
              furnitureList.add(furniture);
              Log.d("c18",s);
          }
          catch (JSONException e) 
          {
              e.printStackTrace();
              Log.e("c19",s);
          }
      }
  
      return furnitureList;
  }    
  
  private HashMap&lt;String, Object&gt; getFurniture(JSONObject jFurniture)
  {
      HashMap&lt;String, Object&gt; furniture = new HashMap&lt;String, Object&gt;();
      String furnitureName = "";
      String flag="";
      String language = "";
      try
      {
          furnitureName = jFurniture.getString("furniture_name");
          flag = jFurniture.getString("furniture_image");
          language = jFurniture.getString("furniture_cost");
          String details =        "Language : " + language + "\n"
          furniture.put("furniture", furnitureName);
          furniture.put("flag", R.drawable.blank);
          furniture.put("flag_path", flag);
          furniture.put("details", details);
          Log.d("c20",s);
  
      } catch (JSONException e) 
      {
          e.printStackTrace();
          Log.e("c21",s);
      }
      return furniture;
  }
  }
  </code></pre>
  
  <p>furniture.php file</p>
  
  <p>the php file that fetch the info from the database and send to android</p>
  
  <pre><code>&lt;?php
  include('config.php');
  date_default_timezone_set("Asia/Calcutta");
  
  $result1 = mysqli_query($con,"SELECT furniture_name, furniture_image, furniture_cost FROM tbl_furniture");
  
  while($row=mysqli_fetch_array($result1))
  {
      //$row['store_name'];
      //echo"&lt;br&gt;";
      $back_android[]=$row;
  }
  
  print(json_encode($back_android));
  
  ?&gt;
  </code></pre>
  
  <p>furniture.xml file</p>
  
  <p>the layout of the furniture file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:gravity="center_vertical"
  tools:context=".MainActivity"
  &gt;
  
  &lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" 
      android:background="@drawable/bg"
  &gt;
  
  
  &lt;Button
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:id="@+id/search"
       android:layout_gravity="center"
       android:text="Search for Furniture"
       android:textSize="10dp"
       android:textColor="#AAAAAA"
   /&gt;
  
  &lt;TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/sf"
       android:layout_gravity="center"
       android:text="Select Furniture"
       android:textSize="20dp"
       android:textColor="#FFFFFF"
   /&gt;
  
      &lt;ListView
          android:id="@+id/flist"
          android:layout_width="fill_parent"
          android:layout_height="402dp"
          android:layout_marginTop="10dp"
          android:layout_weight="0.18" &gt;
      &lt;/ListView&gt;
  
  
  
  &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>f_item.xml file</p>
  
  <p>Layout of the listview in the furniture.xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" &gt;
  
  &lt;TextView
      android:id="@+id/tv_fur"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:textSize="20dp"
      android:textStyle="bold" /&gt;
  
  &lt;ImageView
      android:id="@+id/iv_icon"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/tv_fur"
      android:layout_centerVertical="true"
      android:padding="5dp"
      android:contentDescription="@string/str_iv_flag" /&gt;
  
  &lt;TextView
      android:id="@+id/tv_fur_details"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_toRightOf="@id/iv_icon"
      android:layout_below="@id/tv_fur"  /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>