title: JSON null Object Reference Error {Android}
body: <p>I have made an application by this tutorial
  <a href="http://javatechig.com/android/json-feed-reader-in-android" rel="nofollow noreferrer">http://javatechig.com/android/json-feed-reader-in-android</a></p>
  
  <p>but when I run app in android studio there are following errors</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
              at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
              at org.json.JSONTokener.nextValue(JSONTokener.java:94)
              at org.json.JSONObject.&lt;init&gt;(JSONObject.java:156)
              at org.json.JSONObject.&lt;init&gt;(JSONObject.java:173)
              at com.example.administrator.myapplication5.FeedListActivity.getJSONFromUrl(FeedListActivity.java:127)
              at com.example.administrator.myapplication5.FeedListActivity$DownloadFilesTask.doInBackground(FeedListActivity.java:85)
              at com.example.administrator.myapplication5.FeedListActivity$DownloadFilesTask.doInBackground(FeedListActivity.java:67)
              at android.os.AsyncTask$2.call(AsyncTask.java:288)
              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p>This is FeedListActivity class</p>
  
  <pre><code>public class FeedListActivity extends Activity {
  
      private ArrayList&lt;FeedItem&gt; feedList = null;
      private ProgressBar progressbar = null;
      private ListView feedListView = null;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_posts_list);
          progressbar = (ProgressBar) findViewById(R.id.progressBar);
          String url = "http://javatechig.com/api/get_category_posts/?dev=1&amp;slug=android";
          new DownloadFilesTask().execute(url);
      }
  
      public void updateList() {
          feedListView= (ListView) findViewById(R.id.custom_list);
          feedListView.setVisibility(View.VISIBLE);
          progressbar.setVisibility(View.GONE);
  
          feedListView.setAdapter(new CustomListAdapter(this, feedList));
          feedListView.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
                  Object o = feedListView.getItemAtPosition(position);
                  FeedItem newsData = (FeedItem) o;
  
                  Intent intent = new Intent(FeedListActivity.this, FeedDetailsActivity.class);
                  intent.putExtra("feed", newsData);
                  startActivity(intent);
              }
          });
      }
  
      private class DownloadFilesTask extends AsyncTask&lt;String, Integer, Void&gt; {
  
          @Override
          protected void onProgressUpdate(Integer... values) {
          }
  
          @Override
          protected void onPostExecute(Void result) {
              if (null != feedList) {
                  updateList();
              }
          }
  
          @Override
          protected Void doInBackground(String... params) {
              String url = params[0];
  
              // getting JSON string from URL
              JSONObject json = getJSONFromUrl(url);
  
              //parsing json data
              parseJson(json);
              return null;
          }
      }
  
  
      public JSONObject getJSONFromUrl(String url) {
          InputStream is = null;
          JSONObject jObj = null;
          String json = null;
  
          // 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();
  
              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 (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          try {
              jObj = new JSONObject(json);
          } catch (JSONException e) {
              Log.e("JSON Parser", "Error parsing data " + e.toString());
          }
  
          // return JSON String
          return jObj;
  
      }
  
      public void parseJson(JSONObject json) {
          try {
  
              // parsing json object
              if (json.getString("status").equalsIgnoreCase("ok")) {
                  JSONArray posts = json.getJSONArray("posts");
  
                  feedList = new ArrayList&lt;FeedItem&gt;();
  
                  for (int i = 0; i &lt; posts.length(); i++) {
                      JSONObject post = (JSONObject) posts.getJSONObject(i);
                      FeedItem item = new FeedItem();
                      item.setTitle(post.getString("title"));
                      item.setDate(post.getString("date"));
                      item.setId(post.getString("id"));
                      item.setUrl(post.getString("url"));
                      item.setContent(post.getString("content"));
                      JSONArray attachments = post.getJSONArray("attachments");
  
                      if (null != attachments &amp;&amp; attachments.length() &gt; 0) {
                          JSONObject attachment = attachments.getJSONObject(0);
                          if (attachment != null)
                              item.setAttachmentUrl(attachment.getString("url"));
                      }
  
                      feedList.add(item);
                  }
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>Also, I found this answer (<a href="https://stackoverflow.com/questions/19711870/android-strange-error/29874561?noredirect=1#comment47874419_29874561">Android strange error</a>) but it didn't work </p>
  
  <p>I would be thankful to consider this error and help me to solve that.</p>