空指針異常沒有爲ItemizedOverlay下面的代碼:添加此疊加MapView類與添加新的覆蓋到的MapView
private class AppointmentsOverlay extends ItemizedOverlay {
private List<OverlayItem> locations;
public AppointmentsOverlay(Drawable defaultMarker, List<Address> addresses) {
super(defaultMarker);
locations=new ArrayList<OverlayItem>();
convertAddressesToOverlayItems(addresses);
}
private void convertAddressesToOverlayItems(List<Address> addresses) {
for (Address address:addresses) {
GeoPoint gp=new GeoPoint((int)(address.getLatitude()*1000000),
(int)(address.getLongitude()*1000000));
locations.add(new OverlayItem(gp, "1", "1"));
}
}
@Override
protected OverlayItem createItem(int i) {
return locations.get(i);
}
@Override
public int size() {
return locations.size();
}
}
和下面的代碼:
private void initializeMapWithAppointments(List<Address> addresses) {
Drawable marker=getResources().getDrawable(R.drawable.marker);
mMapViewAppointments.getOverlays().add(new AppointmentsOverlay(marker, addresses));
//mMapViewAppointments.setClickable(false);
}
如果我通過的MapView點擊我以下異常消息:
04-09 19:57:36.948: E/MapActivity(7053): Couldn't get connection factory client
04-09 19:57:41.263: E/AndroidRuntime(7053): FATAL EXCEPTION: main
04-09 19:57:41.263: E/AndroidRuntime(7053): java.lang.NullPointerException
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.google.android.maps.MapView.onTouchEvent(MapView.java:679)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.View.dispatchTouchEvent(View.java:5579)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1720)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1692)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1692)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1692)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1965)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1692)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1983)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1442)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.app.Activity.dispatchTouchEvent(Activity.java:2421)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1931)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.View.dispatchPointerEvent(View.java:5759)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2970)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2529)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:869)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2538)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.os.Looper.loop(Looper.java:154)
04-09 19:57:41.263: E/AndroidRuntime(7053): at android.app.ActivityThread.main(ActivityThread.java:4945)
04-09 19:57:41.263: E/AndroidRuntime(7053): at java.lang.reflect.Method.invokeNative(Native Method)
04-09 19:57:41.263: E/AndroidRuntime(7053): at java.lang.reflect.Method.invoke(Method.java:511)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-09 19:57:41.263: E/AndroidRuntime(7053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-09 19:57:41.263: E/AndroidRuntime(7053): at dalvik.system.NativeStart.main(Native Method)
我不明白這意味着什麼,因爲我看不到我的ñ也可以自定義ItemizedOverlay。我已經添加了API key,並且看到空的MapView。請告訴我,我該如何解決它?謝謝。
我想我不需要重寫這個方法... – user2218845 2013-04-09 16:03:00