NullPointerException with Clusterer Makers, Using Clusterer Library

93 views Asked by At

I have an error when I try to implement this library https://github.com/mrmans0n/clusterer.

I receive a NullPointerException and I don't know why, if anybody can help me with this please.

FATAL EXCEPTION: main java.lang.NullPointerException
        at io.nlopez.clusterer.QuadTreeBoundingBox.containsData(QuadTreeBoundingBox.java:51)
        at io.nlopez.clusterer.QuadTree$QuadTreeNode.insertData(QuadTree.java:99)
        at io.nlopez.clusterer.QuadTree.insertData(QuadTree.java:33)
        at io.nlopez.clusterer.Clusterer.addAll(Clusterer.java:148)
        at greatlifedevelopers.studentrental.fragments.MapsV2General.initClusterer(MapsV2General.java:358)
        at greatlifedevelopers.studentrental.fragments.MapsV2General.moveMap(MapsV2General.java:353)
        at greatlifedevelopers.studentrental.fragments.MapsV2General.access$300(MapsV2General.java:57)
        at greatlifedevelopers.studentrental.fragments.MapsV2General$AllAlojamientos.onPostExecute(MapsV2General.java:341)
        at greatlifedevelopers.studentrental.fragments.MapsV2General$AllAlojamientos.onPostExecute(MapsV2General.java:231)
        at android.os.AsyncTask.finish(AsyncTask.java:602)
        at android.os.AsyncTask.access$600(AsyncTask.java:156)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4441)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
        at dalvik.system.NativeStart.main(Native Method)

This is my AsynTask where I populate the List

public class AllAlojamientos extends AsyncTask<String, String, String>{
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(MapsV2General.this.getActivity());
        pDialog.setMessage("Please wait a moment..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... args) {

            pointAlojamientoses = new ArrayList<PointAlojamientos>();

            List<NameValuePair> params = new ArrayList<NameValuePair>();

            JSONObject json = jParser.makeHttpRequest(url_todos_alojamientos, "GET", params);
            /*JSONObject jsons = jParser.makeHttpRequest(url_todos_servicios, "GET", params);*/

            try{
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {

                    alojamiento = json.getJSONArray(TAG_ALOJAMIENTO);

                    for (int i = 0; i < alojamiento.length(); i++) {
                        JSONObject c = alojamiento.getJSONObject(i);

                        name = c.getString(TAG_NOMBRE);
                        directions = c.getString(TAG_DIRECCION);

                        pointAlojamientoses.add(new PointAlojamientos(new LatLng(Double.parseDouble(c.getString(TAG_LATITUD)), Double.parseDouble(c.getString(TAG_LONGITUD))), name, directions));

                    }

                } else {
                    //
                }

            } catch (JSONException e){
                pDialog.dismiss();
                e.printStackTrace();
            } catch (NullPointerException e){
                pDialog.dismiss();
            }

       return null;
    }

    @Override
    protected void onPostExecute(String a) {
        super.onPostExecute(a);
        pDialog.dismiss();

        moveMap();
        initClusterer();

    }
}

and here's my initClusterer where I receive an error.

private void initClusterer() {
    clusterer = new Clusterer<PointAlojamientos>(this.getActivity(), googleMap);
    clusterer.addAll(pointAlojamientoses);

    clusterer.setAnimationEnabled(true);
    clusterer.setMarkerAnimation(new MarkerAnimation() {
        @Override
        public void animateMarker(Marker marker, float interpolation) {
            // Basic fading animation
            marker.setAlpha(interpolation);
        }
    });


    clusterer.setClustererListener(new Clusterer.ClustererClickListener<PointAlojamientos>() {

        @Override
        public void markerClicked(PointAlojamientos marker) {
            Log.e("Cluster", "marker clicked");
        }

        @Override
        public void clusterClicked(io.nlopez.clusterer.Cluster position) {
            Log.e("Clusterer", "cluster clicked");

        }
    });

    clusterer.setOnPaintingMarkerListener(new OnPaintingClusterableMarkerListener<PointAlojamientos>() {

        @Override
        public void onMarkerCreated(Marker marker, PointAlojamientos clusterable) {

        }


        @Override
        public MarkerOptions onCreateMarkerOptions(PointAlojamientos poi) {
            return new MarkerOptions().position(poi.getPosition()).title(poi.getName()).snippet(poi.getDescription());
        }


    });

    clusterer.setOnPaintingClusterListener(new OnPaintingClusterListener<PointAlojamientos>() {

        @Override
        public void onMarkerCreated(Marker marker, io.nlopez.clusterer.Cluster<PointAlojamientos> cluster) {

        }

        @Override
        public MarkerOptions onCreateClusterMarkerOptions(io.nlopez.clusterer.Cluster<PointAlojamientos> cluster) {
            return new MarkerOptions()
                    .title("Clustering" + cluster.getWeight() + "items")
                    .position(cluster.getCenter())
                    .icon(BitmapDescriptorFactory.fromBitmap(getClusteredLabel(cluster.getWeight(), getActivity())));
        }
    });

}
0

There are 0 answers