title: Error when parsing JSON Data from my URL
body: <p>I'm developing an android application based on remote database , I found solutions on how to put data in the database but I'm having much problems on getting it back.
  When I open the activity that gets the data the app crash. I couldn't localise where the error is in my code!! so here is my code and I hope you can help me .
  Thank you.</p>
  
  <p>This is "Acceuil"  class that has 1 button to open "Professors" class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  
  //in this class I'm just defining a button that will open another class to get data from the database.
  
  public class Acceuil extends Activity  {
   
   
   Button b1;
   
  
   protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.acceuil);
    
    b1 = (Button) findViewById(R.id.button3);
    
    b1.setOnClickListener(new OnClickListener() {
     
     @Override
     public void onClick(View arg0) {
      // TODO Auto-generated method stub
     
      Intent i = new Intent(getApplicationContext(), Professors.class);
      startActivity(i);
      
     }
    });
    
    
    
    
    
  
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is the "Professors"  class that crashes my app.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class Professors extends Activity {
   
   
   
   //URL to get JSON Array
    private static  String url = "http://waelhamda.host22.com/comments.php";
    
    //JSON Node Names 
    private static final String TAG_USER = "posts";
    private static final String TAG_ID = "last";
    
    
    JSONArray user = null;
  
  
  
       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
         
           setContentView(R.layout.professors);
           
     // Creating new JSON Parser
     JSONParser jParser = new JSONParser();
  
     // Getting JSON from URL
     JSONObject json = jParser.getJSONFromUrl(url);
     
     try {
      // Getting JSON Array
      user = json.getJSONArray(TAG_USER);
      JSONObject c = user.getJSONObject(0);
      
      // Storing  JSON item in a Variable
      String id = c.getString(TAG_ID);
     
      
      //Importing TextView
      final TextView uid = (TextView)findViewById(R.id.pro1);
     
      
      //Set JSON Data in TextView
      uid.setText(id);
      
  
     
    } catch (JSONException e) {
     e.printStackTrace();
    }
  
      
  
       }
  
  
    
       
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is the "JSONParser" class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.UnsupportedEncodingException;
  import java.util.List;
   
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.client.utils.URLEncodedUtils;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  
   
  import android.util.Log;
   
  public class JSONParser {
   
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
   
      // constructor
      public JSONParser() {
   
      }
   
      
      
      
     
  
       public JSONObject getJSONFromUrl(String url) {
  
        // Making HTTP request
        try {
         // defaultHttpClient
         DefaultHttpClient httpClient = new DefaultHttpClient();
         HttpPost httpPost = new HttpPost(url);
  
         HttpResponse httpResponse = httpClient.execute(httpPost);
         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"), 8);
         StringBuilder sb = new StringBuilder();
         String line = null;
         while ((line = reader.readLine()) != null) {
          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 JSONObject(json);
        } catch (JSONException e) {
         Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
  
        // return JSON String
        return jObj;
  
       }
      
      
      
      
      
      
      
      // function get json from url
      // by making HTTP POST or GET mehtod
      public JSONObject makeHttpRequest(String url, String method,
              List&lt;NameValuePair&gt; params) {
   
          // Making HTTP request
          try {
   
              // check for request method
              if(method == "POST"){
                  // request method is POST
                  // defaultHttpClient
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpPost httpPost = new HttpPost(url);
                  httpPost.setEntity(new UrlEncodedFormEntity(params));
   
                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
   
              }else if(method == "GET"){
                  // request method is GET
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  String paramString = URLEncodedUtils.format(params, "utf-8");
                  url += "?" + paramString;
                  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"), 8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  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 JSONObject(json);
          } catch (JSONException e) {
              Log.e("JSON Parser", "Error parsing data " + e.toString());
          }
   
          // return JSON String
          return jObj;
   
      }
  
   
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And finally this is the manifest file of the app.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.wael.enimcommunity"
      android:versionCode="1"
      android:versionName="1.0" &gt;
      
      
  &lt;meta-data android:name="com.google.android.backup.api_key" 
          android:value="AEdPqrEAAAAIdPJ8uLgoiErqlZNYU5_jN_d8O8VPPtfbbF5MRQ" /&gt;
  
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="21" /&gt;
      
       &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  
      &lt;uses-permission 
          android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.wael.enimcommunity.Login"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.wael.enimcommunity.Register"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.wael.enimcommunity.Acceuil"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.wael.enimcommunity.JSONParser"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.wael.enimcommunity.GPSTracker"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.wael.enimcommunity.Events"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.wael.enimcommunity.Professors"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name="com.wael.enimcommunity.Portail"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.wael.enimcommunity.Schedule"
              android:label="@string/app_name"  &gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I hope those informations are enough to solve my problem. Thanx again my friends. </p>