0

マップ上に複数のピンの場所、つまり自分の場所とクラウド サーバーから取得した別の場所を表示しようとしています。

以下のコードに基づいています。

文字列をトークン化しようとすると、NullPointer エラー メッセージが表示され続けます。これは、私の CloudTask アクティビティが決して起動されないことを意味します....理由がわかりませんし、Eclipse デバッガーがスレッドをステップスルーしません...助けていただければ幸いです。

    public class MapsActivity extends com.google.android.maps.MapActivity {
    private static final String TAG = null;


    private MapController mapController;
    private MapView mapView;
    private LocationManager locationManager;
    private MyOverlays itemizedoverlay;
    private MyLocationOverlay myLocationOverlay;
    private MyLocationOverlay otherLocationOverlay;
    private Handler handler;

    private String message;
    StringTokenizer tokens;

    Integer p1 = null;
    Integer p2;

    GeoPoint point;
    static Context mContext = null;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.main); // bind the layout to the activity


            // Configure the Map
            mapView = (MapView) findViewById(R.id.mapview);
            mapView.setBuiltInZoomControls(true);
            mapView.setSatellite(true);
            mapController = mapView.getController();
            mapController.setZoom(14); // Zoon 1 is world view
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);


            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2500,
                    0,(LocationListener) new GeoUpdateHandler());
                    //new Intent("android.intent.action.LOCATION_CHANGED"); 
                    //(LocationListener) new GeoUpdateHandler());

            myLocationOverlay = new MyLocationOverlay(this, mapView);


            mapView.getOverlays().add(myLocationOverlay);


            handler = new Handler();
        //  new AsyncTask<Void, Void, String>() {
            myLocationOverlay.runOnFirstFix(new Runnable(){ 
             public void run(){



                    MyRequestFactory requestFactory = Util.getRequestFactory(mContext,
                            MyRequestFactory.class);
                    final CloudTask1Request request = requestFactory.cloudTask1Request();
                    Log.i(TAG, "Sending request to server");


                    request.queryTasks().fire(new Receiver<List<TaskProxy>>() {


                        @Override
                        public void onSuccess(List<TaskProxy> taskList) {
                            //message = result;


                            message = "\n";

                            for (TaskProxy task : taskList) {

                                message += task.getId()+","+task.getNote()+",";                                 

                            }


                        }
                    });
                    //return message;
                //}



                        if(message.length() == 0){

                            Log.i("MESSAGE","Did not get any points from cloud");
                        }

                    tokens = new StringTokenizer(message,",");


                     tokens.nextToken();
                     p1 = Integer.parseInt(tokens.nextToken());
                     p2 = Integer.parseInt(tokens.nextToken());
                     point = new GeoPoint(p1,p2);

                     mapView.getController().animateTo(point);


        }


    });

             Drawable drawable = this.getResources().getDrawable(R.drawable.pushpin);
                itemizedoverlay = new MyOverlays(this, drawable);
                createMarker();

            myLocationOverlay.runOnFirstFix(new Runnable() {
                public void run() {
                    mapView.getController().animateTo(
                            myLocationOverlay.getMyLocation());
                }
            });

            //Drawable drawable = this.getResources().getDrawable(R.drawable.pushpin);
            itemizedoverlay = new MyOverlays(this, drawable);
            createMarker();


    }




    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    public class GeoUpdateHandler implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
            int lat = (int) (location.getLatitude() * 1E6);
            int lng = (int) (location.getLongitude() * 1E6);
            GeoPoint point = new GeoPoint(lat, lng);
            createMarker();
            mapController.animateTo(point); // mapController.setCenter(point);

        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }


    }

    private void createMarker() {
        GeoPoint p = mapView.getMapCenter();
        OverlayItem overlayitem = new OverlayItem(p, "", "");
        itemizedoverlay.addOverlay(overlayitem);
        if (itemizedoverlay.size() > 0) {
            mapView.getOverlays().add(itemizedoverlay);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        myLocationOverlay.enableMyLocation();
        myLocationOverlay.enableCompass();
    }

    @Override
    protected void onPause() {
        super.onResume();
        myLocationOverlay.disableMyLocation();
        myLocationOverlay.disableCompass();
    }


} 
4

1 に答える 1

0

これらを onSuccess() の中に入れます

if(message.length() == 0){

    Log.i("MESSAGE","Did not get any points from cloud");
}

tokens = new StringTokenizer(message,",");


tokens.nextToken();
p1 = Integer.parseInt(tokens.nextToken());
p2 = Integer.parseInt(tokens.nextToken());
point = new GeoPoint(p1,p2);

mapView.getController().animateTo(point);
于 2012-04-06T08:59:16.213 に答える