title: JSON Android Error- Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.getString(java.lang.String)' on a null object reference
body: <p>My app is crashing and the log is showing this error: </p>
  
  <p>Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.getString(java.lang.String)' on a null object reference on the line where I do:</p>
  
  <pre><code>ab = jobj.getString("title");
  </code></pre>
  
  <p>I'm a noob to Android development. Please help!</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
  JSONObject jobj = null;
  ClientServerInterface clientServerInterface = new ClientServerInterface();
  TextView textView;
  String ab = "";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      textView = (TextView) findViewById(R.id.textView);
      new RetrieveData().execute();
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings)
      {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  class RetrieveData extends AsyncTask&lt;String,String,String&gt;
  {
      protected String doInBackground(String... arg0) {
          jobj = clientServerInterface.makeHttpRequest("http://**.***.***.**/printresult.php");
          try {
              ab = jobj.getString("title");
          } catch (JSONException e) {
              e.printStackTrace();
          }
          return ab;
      }
  
      protected void onPostExecute(String ab){
          textView.setText(ab);
      }
  }
  }
  </code></pre>
  
  <p>Here's the other file:</p>
  
  <pre><code>public class ClientServerInterface {
  
  static InputStream is = null;
  static JSONObject jobj = null;
  static String json = "";
  
  
  public ClientServerInterface(){
  }
  public JSONObject makeHttpRequest(String url){
      DefaultHttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost(url);
      try{
          HttpResponse httpresponse = httpclient.execute(httppost);
          HttpEntity httpentity = httpresponse.getEntity();
          is = httpentity.getContent();
      }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;
          try{
              while((line = reader.readLine())!= null){
                  sb.append(line+"\n");
              }
              is.close();
              json = sb.toString();
              try{
                  jobj = new JSONObject(json);
              }catch (JSONException e){
                  e.printStackTrace();
              }
          }catch(IOException e){
              e.printStackTrace();
          }
      }catch (UnsupportedEncodingException e){
          e.printStackTrace();
      }
      return jobj;
  }
  }
  </code></pre>
  
  <p>Maybe it is in my php file?</p>
  
  <pre><code>&lt;?php
  require_once('connection.php');
  
  $qry = "SELECT * FROM eventdetails";
  $result = mysql_query($qry);
  $rows = array();
  while($r = mysql_fetch_assoc($result)){
  $rows[] = $r;
  }
  echo json_encode($rows);
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>I'm really stumped. Please help!</p>