【发布时间】:2013-01-10 11:24:12
【问题描述】:
我在创建自己的 CustomInfoWindow 时遇到问题。不知道在哪里以及为什么会出现异常
这是我的简单 customInfoWindow 类
public class CustomInfoWindow implements InfoWindowAdapter {
private LayoutInflater mInflater;
public CustomInfoWindow(LayoutInflater inflater) {
this.mInflater=inflater;
}
@Override
public View getInfoContents(Marker marker) {
View popup = mInflater.inflate(R.layout.info_window_layout, null);
TextView tv=(TextView)popup.findViewById(R.id.title);
tv.setText(marker.getTitle());
tv=(TextView)popup.findViewById(R.id.address);
tv.setText(marker.getSnippet());
return popup;
}
@Override
public View getInfoWindow(Marker marker) {
View popup = mInflater.inflate(R.layout.info_window_layout, null);
TextView tv=(TextView)popup.findViewById(R.id.title);
tv.setText(marker.getTitle());
tv=(TextView)popup.findViewById(R.id.address);
tv.setText(marker.getSnippet());
return popup;
}
}
我在这里设置。 (主活动)
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
Statics.LAT_TLV, Statics.LON_TLV), 13));
CustomInfoWindow customInfoWindow = new CustomInfoWindow(getLayoutInflater());
mMap.setInfoWindowAdapter(customInfoWindow);
我没有实现 onMarkerClick 方法。 地图可以使用标记(大约 40 个)加载,但是当我单击其中一个标记时,我得到:
01-10 13:15:24.321: E/AndroidRuntime(21162): FATAL EXCEPTION: main
01-10 13:15:24.321: E/AndroidRuntime(21162): java.lang.NullPointerException
01-10 13:15:24.321: E/AndroidRuntime(21162): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at android.view.View.measure(View.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.y.i(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.y.a(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.w.a(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.bd.a(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.y.bw.b(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.y.bw.a(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.dh.a(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.n.c(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.dw.a(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.bd.c(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.a.dq.onSingleTapConfirmed(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.e.v.onSingleTapConfirmed(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at maps.e.j.handleMessage(Unknown Source)
01-10 13:15:24.321: E/AndroidRuntime(21162): at android.os.Handler.dispatchMessage(Handler.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at android.os.Looper.loop(Looper.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at android.app.ActivityThread.main(ActivityThread.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 13:15:24.321: E/AndroidRuntime(21162): at java.lang.reflect.Method.invoke(Method.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
01-10 13:15:24.321: E/AndroidRuntime(21162): at dalvik.system.NativeStart.main(Native Method)
如果有人可以帮助我,我将不胜感激,如果有一个非常简单的示例说明如何创建自己的信息视图,那就太好了。非常感谢。乌迪
【问题讨论】:
-
我有完全相同的错误,如果我使用 getInfoContents 一切都很好,但如果我尝试 getInfoWindows,应用程序崩溃。
标签: android google-maps-android-api-2 infoview