アンドロイド上に地図のオーバーレイを描画する

public void draw(Canvas canvas, MapView mapView, boolean shadow) {    

// Get the map projection to convert lat/long to screen coordinates
Projection projection = mapView.getProjection();

Point lPoint = new Point();
//  projection.toPixels(locationPoint, lPoint);

// Draw the overlay
if (shadow == false) {
  if (friendLocations.size() > 0) {
    Iterator e = friendLocations.keySet().iterator();
    do {
     //Get the name and location of each contact
      String name = e.next();          
      Location location = friendLocations.get(name);
      if(location!=null)
     {
     //Convert the lat/long to a Geopoint
      Double latitude = location.getLatitude()*1E6;
      Double longitude = location.getLongitude()*1E6;
      //GeoPoint geopoint = new GeoPoint(latitude.intValue(),longitude.intValue());
      GeoPoint geopoint = new GeoPoint(19240000,-99120000); 
     //Ensure each contact is within 10km
      float dist = location.distanceTo(getLocation()); 
      if (dist < 10000) {
      Point point = new Point();
       projection.toPixels(geopoint, point);

       //Draw a line connecting the contact to your current location.
        canvas.drawLine(lPoint.x, lPoint.y, point.x, point.y, paint);

       //Draw a marker at the contact's location.
        RectF oval = new RectF(point.x-markerRadius,
                               point.y-markerRadius,
                               point.x+markerRadius,
                               point.y+markerRadius);

        canvas.drawOval(oval, backPaint);
        oval.inset(2, 2);
        canvas.drawOval(oval, paint);

       //Draw the contact's name next to their position.
        float textWidth = paint.measureText(name);
        float textHeight = paint.getTextSize();
        RectF textRect = new RectF(point.x+markerRadius, point.y-textHeight,
                                   point.x+markerRadius+8+textWidth, point.y+4);
        canvas.drawRoundRect(textRect, 3, 3, backPaint);
        canvas.drawText(name, point.x+markerRadius+4, point.y, paint);
      }
     }
    } while (e.hasNext());
  }
}
super.draw(canvas, mapView, shadow);
}

Can anyone tell me whats wrong with the above code snippet.
The logcat displayes java.lang.Nullpointer exception at the function distanceTo

私は場所のオブジェクトに初期座標を提供し、直接ジオポイントを初期化するようなものは、何も動作しないようなすべての選択肢を試しました。

1
getLocation()のコードを投稿しますか?例外に基づいて、そのメソッドはnullを返す必要があります。
追加された 著者 Chris,
高すぎる...どうにかして私の機能はクラスの私的なデータにアクセスすることができませんでした!
追加された 著者 user1064566,

答えはありません

0