Json object parsing error using http request
<p>I am having an issue when <code>http request</code> is attempted the code that does the parsing works well...i tried to put a sample <code>json</code> string into the variable result and commented out all the code related to <code>http request</code>...i found the code works fine.But when i do a http request it is not working.Thank you in advance.The following is my code
`</p>

<pre><code>public class MainActivity extends AppCompatActivity  {

    String result = "";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         onclick();
    }




    public void onclick(){
        Asynctaskrunner run = new Asynctaskrunner();
        run.execute("http://headers.jsontest.com/");
        TextView text = (TextView) findViewById(R.id.textView);
        TextView text1 = (TextView) findViewById(R.id.textView2);
        final TextView text2= (TextView) findViewById(R.id.textView5);
        final TextView text3 = (TextView) findViewById(R.id.textView6);
        Button button = (Button) findViewById(R.id.button);

        button.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try {

                            JSONObject json = new JSONObject(result);

                            String name = json.getString("Accept-Language");
                            String salary = json.getString("Host");
                            text2.setText(name);
                            text3.setText(salary);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }
        );



    }
    //-----------------------------------
    private class Asynctaskrunner extends AsyncTask&lt;String,Void,Void&gt;{

        private String response;

        @Override
        protected Void doInBackground(String... params) {
            try {
                URL url = new URL(params[0]);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                InputStream in = new BufferedInputStream(conn.getInputStream());
                response=convertStreamToString(in);

            }  catch (MalformedURLException e) {
                Log.e(TAG, "MalformedURLException: " + e.getMessage());
            } catch (ProtocolException e) {
                Log.e(TAG, "ProtocolException: " + e.getMessage());
            } catch (IOException e) {
                Log.e(TAG, "IOException: " + e.getMessage());
            } catch (Exception e) {
                Log.e(TAG, "Exception: " + e.getMessage());
            }


            result=response;
            TextView textView = (TextView) findViewById(R.id.textView4);

            return null;
        }


        private String convertStreamToString(InputStream is) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();

            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append('\n');
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return sb.toString();
        }


    }

}`
</code></pre>