使用Clusterer库的Clusterer Makers的NullPointerException

时间:2015-06-11 21:39:42

标签: android nullpointerexception google-maps-markers google-maps-android-api-2 markerclusterer

我尝试实施此库https://github.com/mrmans0n/clusterer时出错。

我收到NullPointerException并且我不知道为什么,如果有人可以帮我解决这个问题。

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)

这是我填充List

的AsynTask
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();

    }
}

这是我的initClusterer,我收到错误。

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 个答案:

没有答案