title: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
body: <p>Every time I open my app it crashes because of this error I dont know what should I do please help me... I have also attached logcat screen shot below and the java class in which the error is comming.</p>
  
  <p>DataParser.java:</p>
  
  <pre><code>public class DataParser {
  
      private HashMap&lt;String,String&gt; getPlace(JSONObject googlePlacesJson){
          HashMap&lt;String,String&gt; googlePlaceMap=new HashMap&lt;&gt;();
  
          String placeName="-NA-";
          String vicinity="-NA-";
          String latitude="";
          String logitude="";
          String reference="";
          List&lt;HashMap&lt;String,String&gt;&gt; placesList=new ArrayList&lt;&gt;();
  
  
          try {
          if(!googlePlacesJson.isNull("name")){
  
                  placeName=googlePlacesJson.getString("name");
  
          }
          if (!googlePlacesJson.isNull("vicinity")){
              vicinity=googlePlacesJson.getString("vicinity");
          }
          latitude=googlePlacesJson.getJSONObject("geometry").getJSONObject("location").getString("lat");
          logitude=googlePlacesJson.getJSONObject("geometry").getJSONObject("location").getString("lng");
          reference=googlePlacesJson.getString("reference");
  
          googlePlaceMap.put("name",placeName);
          googlePlaceMap.put("vicinity",vicinity);
          googlePlaceMap.put("lat",latitude);
          googlePlaceMap.put("lng",logitude);
          googlePlaceMap.put("reference",reference);
  
  
  
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return googlePlaceMap;
      }
  
      private List&lt;HashMap&lt;String,String&gt;&gt; getPlaces(JSONArray jsonArray){
          long count;
         count=jsonArray.length(); // error comes on this line
          List&lt;HashMap&lt;String,String&gt;&gt; placesList=new ArrayList&lt;&gt;();
          HashMap&lt;String,String&gt; placeMap=null;
  
          for(int i=0;i&lt;count;i++){
              try {
                  placeMap=getPlace((JSONObject) jsonArray.get(i));
                  placesList.add(placeMap);
  
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
          return placesList;
      }
  
      public List&lt;HashMap&lt;String,String&gt;&gt; parse(String jsonData){
          JSONArray jsonArray=null;
          JSONObject jsonObject;
  
          try {
              jsonObject=new JSONObject(jsonData);
              jsonArray=jsonObject.getJSONArray("results");
  
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return getPlaces(jsonArray);
  
      }
  
  }
  </code></pre>
  
  <p>this is the screen shot my my log cat:</p>
  
  <p><a href="https://i.stack.imgur.com/slPTA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/slPTA.png" alt="enter image description here"></a></p>