title: How do I parse the url in the given code to read as per the output defined in the code?
body: <p>I am new to android and I want to parse url using <code>json</code>. I get exceptions when I run the code and my application says unfortunately myapp has stopped running. I have also posted my <code>logcat</code>. I want to read<br>
  Course code:101,<br>
  Course title :  "blahblah"<br>
  Semesters offered : Semester 1, Semester 2, Semester 3</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLConnection;
  import java.util.ArrayList;
  
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.ResponseHandler;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.BasicResponseHandler;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.params.BasicHttpParams;
  import org.apache.http.params.HttpParams;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.app.Activity;
  import android.app.ListActivity;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class Compsci734MainActivity extends ListActivity {
  
      AsyncTask&lt;Void, Void, Void&gt; mTask;
      String jsonString;
  
      //String url = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&amp;include_rts=true&amp;screen_name=50cent&amp;count=2";
  
      String url = "http://redsox.tcs.auckland.ac.nz/734A/CSService.svc/courses";
  
      //Button b;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_compsci734_main);
          //getActionBar().setDisplayHomeAsUpEnabled(true);
  
          Button button = (Button) findViewById(R.id.btnFetch);
          final TextView tv = (TextView) findViewById(R.id.txtView);
  
          mTask = new AsyncTask&lt;Void, Void, Void&gt; () {
              @Override
              protected Void doInBackground(Void... params) {
                  try {
                      jsonString = getJsonFromServer(url);
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                  return null;
              }
  
              @Override
              protected void onPostExecute(Void result) {
                  super.onPostExecute(result);
  
                  tv.setText(jsonString);
  
              }
          };
  
  //      Button button =(Button) findViewById(R.id.btnFetch);
  //        TextView tv =(TextView) findViewById(R.id.txtView);
          button.setOnClickListener(new OnClickListener() {
  
              public void onClick(View v) {
                  try {
                      String url = "http://redsox.tcs.auckland.ac.nz
                                                    /734A/CSService.svc/courses";
                      HttpPost httppost = new HttpPost(url);
                      try {
                          HttpParams p = new BasicHttpParams();
                          HttpClient httpclient = new DefaultHttpClient(p);
                          ResponseHandler&lt;String&gt; responseHandler = new
                                                          BasicResponseHandler();
                          String responseBody = httpclient.execute(httppost,
                                  responseHandler);
                          JSONArray jArray = new JSONArray(responseBody);
                          String text="";
                          for (int i = 0; i &lt; jArray.length(); i++) {
                              JSONObject e = jArray.getJSONObject(i);
                                  text = text + "Course ID :
                                          "+e.getString("courseField")+"\n";
                                  text = text + "Course name :
                                           "+e.getString("titleField")+"\n";
                                  text = text + "Semesters offered:
                                        "+e.getString("semesterField")+"\n";
                                  //text = text + "Birthyear :
                                  //        "+e.getString("birthyear")+"\n";
                          }
                          Log.i(responseBody, text);
                          tv.setText(text);
                      } catch (ClientProtocolException e) {
                          e.printStackTrace();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
  
                  } catch (Throwable t) {
                      Toast.makeText(getBaseContext(), "Request failed: " +
                                          t.toString(), Toast.LENGTH_LONG).show();
                      t.printStackTrace();
                  }    
  
  
                  //tv.setText(result);
              }
          });
      }
  
  
      public static String getJsonFromServer(String url) throws IOException {
  
          BufferedReader inputStream = null;
  
          URL jsonUrl = new URL(url);
          URLConnection dc = jsonUrl.openConnection();
  
          dc.setConnectTimeout(5000);
          dc.setReadTimeout(5000);
  
          inputStream = new BufferedReader(new InputStreamReader(
                  dc.getInputStream()));
  
          // read the JSON results into a string
          String jsonResult = inputStream.readLine();
          return jsonResult;
      }
  
      }
  </code></pre>
  
  <p><strong>Here is my logcat:</strong></p>
  
  <pre><code>05-13 16:27:16.375: I/dalvikvm(1040): threadid=3: reacting to signal 3
  05-13 16:27:16.585: E/dalvikvm(1040): Unable to open stack trace file '/data/anr/traces.txt': Is a directory
  05-13 16:27:16.585: D/AndroidRuntime(1040): Shutting down VM
  05-13 16:27:16.595: W/dalvikvm(1040): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
  05-13 16:27:16.605: E/AndroidRuntime(1040): FATAL EXCEPTION: main
  05-13 16:27:16.605: E/AndroidRuntime(1040): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.compsci_734p/com.example.compsci_734p.Compsci734MainActivity}: java.lang.RuntimeException: Binary XML file line #7: You must supply a layout_width attribute.
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.os.Handler.dispatchMessage(Handler.java:99)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.os.Looper.loop(Looper.java:137)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.ActivityThread.main(ActivityThread.java:4424)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at java.lang.reflect.Method.invoke(Method.java:511)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at dalvik.system.NativeStart.main(Native Method)
  05-13 16:27:16.605: E/AndroidRuntime(1040): Caused by: java.lang.RuntimeException: Binary XML file line #7: You must supply a layout_width attribute.
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5318)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.view.ViewGroup$MarginLayoutParams.&lt;init&gt;(ViewGroup.java:5439)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.widget.LinearLayout$LayoutParams.&lt;init&gt;(LinearLayout.java:1776)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1700)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:56)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:741)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.Activity.setContentView(Activity.java:1835)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at com.example.compsci_734p.Compsci734MainActivity.onCreate(Compsci734MainActivity.java:50)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.Activity.performCreate(Activity.java:4465)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
  05-13 16:27:16.605: E/AndroidRuntime(1040):     ... 11 more
  05-13 16:27:16.885: I/dalvikvm(1040): threadid=3: reacting to signal 3
  05-13 16:27:16.885: I/dalvikvm(1040): Wrote stack traces to '/data/anr/traces.txt'
  05-13 16:27:17.155: I/dalvikvm(1040): threadid=3: reacting to signal 3
  05-13 16:27:17.165: I/dalvikvm(1040): Wrote stack traces to '/data/anr/traces.txt'
  </code></pre>