title: Android: can not use JSON parse in fragment with asynctask
body: <p>I have a problem when trying to parse JSON data from localhost to fragment android using AsyncTask.</p>
  
  <p><strong>this my code FindPeopleFragment.java</strong></p>
  
  <pre><code>    public class FindPeopleFragment extends Fragment {
      private ProgressDialog pDialog;
      String nim;
      JSONArray str_json = null;
      String surl = "http://10.0.2.2/siakad/jadwal.php?nim=125410295&amp;&amp;jam=10:00 - 12:30";
      TextView isinya;
  
      public FindPeopleFragment(Bundle b){
          nim = b.getString("par_kode");
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
      {
  
          if (container == null)
          {
              return null;
          }
  
  
          View rootView = inflater.inflate(R.layout.fragment_find_people, container, false);
          isinya=(TextView)rootView.findViewById(R.id.isi);
  
          new AmbilData().execute();
          return rootView;
      }
  
      class AmbilData extends AsyncTask&lt;String, Void, JSONObject&gt; {
          String matkul;
          String ruang;
          String dosen;
          String sks;
          String jamkul;
          String kelas;
          String hari;
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(getActivity());
              pDialog.setMessage("Sabar gan, masih ngambil data neh...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(true);
              pDialog.show();
  
  
          }
  
          protected JSONObject doInBackground(String... result) {
              JSONParser jParser = new JSONParser();
              // Getting JSON from URL
              JSONObject json = jParser.AmbilJson(surl);
              return json;
          }
  
  
          @Override
          protected void onPostExecute(JSONObject result) {
            super.onPostExecute(result);
              pDialog.dismiss();
              try {
                  str_json = result.getJSONArray("jadwal");
  
                  for(int i = 0; i &lt; str_json.length(); i++){
                      JSONObject ar = str_json.getJSONObject(i);
  
                      matkul= ar.getString("matkul");
                      sks = ar.getString("sks");
                      hari = ar.getString("hari");
                      jamkul = ar.getString("jam");
                      ruang = ar.getString("ruang");
                      kelas = ar.getString("kelas");
                      dosen = ar.getString("dosen");
  
                      isinya.setText("Matakuliah : "+matkul+
                              "\nSks : "+sks+
                              "\nHari : "+hari+
                              "\nJam : "+jamkul+
                              "\nRuang : "+ruang+
                              "\nKelas : "+kelas+
                              "\nDosen : "+dosen);
  
              } catch (JSONException e) {
                  e.printStackTrace();
                  Log.e("hasil", "Failed data was:\n" + result);
              }
  
          }
      }
  
  }
  </code></pre>
  
  <p><strong>and in my JSONParser.java</strong> </p>
  
  <pre><code>public class JSONParser {
  
  static InputStream is = null;
  static JSONObject jObj = null;
  static String json = "";
  
  // constructor
  public JSONParser() {
  
  }
  
  public JSONObject AmbilJson(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;
  }
  </code></pre>
  
  <p><strong>And I have some errors in my LogCat :</strong></p>
  
  <pre><code>01-31 04:25:46.900: E/AndroidRuntime(2985): FATAL EXCEPTION: AsyncTask #4
  01-31 04:25:46.900: E/AndroidRuntime(2985): java.lang.RuntimeException: An error occured while executing doInBackground()
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.lang.Thread.run(Thread.java:841)
  01-31 04:25:46.900: E/AndroidRuntime(2985): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 58: http://10.0.2.2/siakad/jadwal.php?nim=125410295&amp;&amp;jam=10:00 - 12:30
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.net.URI.create(URI.java:727)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at org.apache.http.client.methods.HttpPost.&lt;init&gt;(HttpPost.java:79)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at sob.akademik.JSONParser.AmbilJson(JSONParser.java:35)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at sob.akademik.FindPeopleFragment$AmbilData.doInBackground(FindPeopleFragment.java:164)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at sob.akademik.FindPeopleFragment$AmbilData.doInBackground(FindPeopleFragment.java:1)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
  01-31 04:25:46.900: E/AndroidRuntime(2985):     ... 4 more
  </code></pre>
  
  <p>please help me to fix this problem. thank you.</p>