我想顯示地圖上的特定位置,以及我想放置圖釘通知的那個特定位置。我已經嘗試了下面的代碼,但它顯示空指針例外,請幫我添加標記。谷歌地圖圖釘錯誤
public class MapDemoActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.pushpin);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mc.animateTo(p);
mc.setZoom(17);
//---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
添加你的logcat並看到第一行。發生nullpointerException .... – 2012-03-09 05:52:22
03-09 11:28:10.430:E/AndroidRuntime(487):引起:java.lang.NullPointerException 03-09 11:28:10.430:E/AndroidRuntime(487):\t在com.MapDemo.MapDemoActivity.onCreate(MapDemoActivity.java:78) 03-09 11:28:10.430:E/AndroidRuntime(487):\t at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 03 -09 11:28:10.430:E/AndroidRuntime(487):\t at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 03-09 11:28:10.430:E/AndroidRuntime(487):\t。 ..更多 – user1196969 2012-03-09 06:01:45
在你的MapDemoActivity.java中看到第78行:78 – 2012-03-09 06:04:05