title: Need to fetch user current details from server
body: <p>I'm new to android location part but did the userA current location posting to the server, but facing quite a bit problem in fetching back the userA location and showing it in userB screen.</p>
  
  <p>What i have done is I'm using the Volley library to fetch the location from the server and posting it in the onMapReady method by auto refreshing the page every 1 sec, but its giving a null pointer exception as 
  NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference.</p>
  
  <p>If my approach is wrong, could you please help me out suggesting one?</p>
  
  <p>This is the code i have implemented in my project</p>
  
  <pre><code>private void fetchLocation(){
          handler.postDelayed(new Runnable() {
              @Override
              public void run() {
                  StringRequest request = new StringRequest(Request.Method.GET, Constant.LocationTrackingURL, new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          try {
                              JSONObject object = new JSONObject(response);
                              JSONArray array = object.getJSONArray("resp");
                              for (int i=0; i&lt;array.length(); i++){
                                  JSONObject jsonObject = array.getJSONObject(i);
                                  newLatitude = jsonObject.getString("loc_latitude").trim();
                                  newLongitude = jsonObject.getString("loc_longitude").trim();
                                  Toast.makeText(MapAct.this, newLatitude+", "+newLongitude, Toast.LENGTH_SHORT).show();
                                  addmarkerToMap(newLatitude, newLongitude);
                              }
                          } catch (JSONException e) {
                              e.printStackTrace();
                              Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                          }
                      }
                  }, new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
  
                      }
                  });
  
                  RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
                  queue.add(request);
              }
          }, 1000);
  
          SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.maps);
          mapFragment.getMapAsync(new OnMapReadyCallback() {
              @Override
              public void onMapReady(GoogleMap googleMap) {
                  Double lat = Double.parseDouble(newLatitude);
                  Double lng = Double.parseDouble(newLongitude);
                  LatLng latLng = new LatLng(lat, lng);
                  googleMap.addMarker(new MarkerOptions().position(latLng).title("I'm here"));
                  CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(17).build();
                  googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
              }
          });
      }
  
      private void addmarkerToMap(String newLat, String newLng){
          double lat = Double.parseDouble(newLat);
          double lng = Double.parseDouble(newLng);
          Toast.makeText(this, "Locations are getting posted as latitude : "+lat+", longitude : "+lng, Toast.LENGTH_SHORT).show();
          MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(lat, lng)).title("I'm Here");
          markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
          mMap.addMarker(markerOptions);
      }
  </code></pre>