Android地图视图错误:您只能在MapActivity中拥有一个MapView

Android地图视图错误:您只能在MapActivity中拥有一个MapView,第1张

概述我正在创建一个带有 *** 作栏和2个标签的应用程序.像这样: Tab1:点击时应显示某个地方的一些细节. Tab2:点击后应显示地图. 我正在使用Fragments. 我的tablistener: private class MyTabListener implements ActionBar.TabListener { @Override public void onT 我正在创建一个带有 *** 作栏和2个标签的应用程序.像这样:

Tab1:点击时应显示某个地方的一些细节.
Tab2:点击后应显示地图.

我正在使用Fragments.

我的tabListener:

private class MyTabListener implements Actionbar.TabListener {        @OverrIDe        public voID onTabSelected(Tab tab,androID.support.v4.app.FragmentTransaction ft) {            // Todo auto-generated method stub            if (tab.getposition() == 0) {                DetailsFragment fragment = new DetailsFragment();                ft.replace(androID.R.ID.content,fragment);            } else {                MapsFragment fragment = new MapsFragment();                ft.replace(androID.R.ID.content,fragment);                //ft.commit();            }        }

MapsFragment.java

public class MapsFragment extends MapFragment {    private MapVIEw map = null;    private MyLocationOverlay me = null;    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) {        return (new FrameLayout(getActivity()));    }    @OverrIDe    public voID onActivityCreated(Bundle savedInstanceState) {        super.onActivityCreated(savedInstanceState);        map = new MapVIEw(getActivity(),"0rQAS47Cicu2t7z4w8Ev6A6de7QlbjvKyi8I-QQ");        map.setClickable(true);        map.getController().setCenter(                getPoint(40.76793169992044,-73.98180484771729));        map.getController().setZoom(17);        map.setBuiltInZoomControls(true);        Drawable marker = getResources().getDrawable(R.drawable.marker);        marker.setBounds(0,marker.getIntrinsicWIDth(),marker.getIntrinsicHeight());        map.getoverlays().add(new SitesOverlay(marker));        me = new MyLocationOverlay(getActivity(),map);        map.getoverlays().add(me);        ((VIEwGroup) getVIEw()).addVIEw(map);    }    @OverrIDe    public voID onResume() {        super.onResume();        me.enableCompass();    }    @OverrIDe    public voID onPause() {        super.onPause();        me.disableCompass();    }    private GeoPoint getPoint(double lat,double lon) {        return (new GeoPoint((int) (lat * 1000000.0),(int) (lon * 1000000.0)));    }    private class SitesOverlay extends itemizedoverlay<OverlayItem> {        private List<OverlayItem> items = new ArrayList<OverlayItem>();        public SitesOverlay(Drawable marker) {            super(marker);            boundCenterBottom(marker);            items.add(new OverlayItem(getPoint(40.748963847316034,-73.96807193756104),"UN","United Nations"));            items.add(new OverlayItem(getPoint(40.76866299974387,-73.98268461227417),"lincoln Center","Home of Jazz at lincoln Center"));            items.add(new OverlayItem(getPoint(40.765136435316755,-73.97989511489868),"CarnegIE Hall","Where you go with practice,practice,practice"));            items.add(new OverlayItem(getPoint(40.70686417491799,-74.01572942733765),"The Downtown Club","Original home of the Heisman Trophy"));            populate();        }        @OverrIDe        protected OverlayItem createItem(int i) {            return (items.get(i));        }        @OverrIDe        protected boolean onTap(int i) {            Toast.makeText(getActivity(),items.get(i).getSnippet(),Toast.LENGTH_SHORT).show();            return (true);        }        @OverrIDe        public int size() {            return (items.size());        }    }}

问题是当我点击地图标签时出现第一次地图.但是,我转到详细信息选项卡,然后再次返回到地图选项卡,我的应用程序崩溃并出现错误

logcat的:

12-04 03:28:02.228: E/AndroIDRuntime(14466): FATAL EXCEPTION: main12-04 03:28:02.228: E/AndroIDRuntime(14466): java.lang.IllegalStateException: You are only allowed to have a single MapVIEw in a MapActivity12-04 03:28:02.228: E/AndroIDRuntime(14466):    at com.Google.androID.maps.MapActivity.setupMapVIEw(MapActivity.java:398)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at com.Google.androID.maps.MapVIEw.<init>(MapVIEw.java:289)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at com.Google.androID.maps.MapVIEw.<init>(MapVIEw.java:235)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at com.m7.nomad.MapsFragment.onCreate(MapsFragment.java:34)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.support.v4.app.FragmentManagerImpl.movetoState(UnkNown Source)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.support.v4.app.FragmentManagerImpl.movetoState(UnkNown Source)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.support.v4.app.BackStackRecord.run(UnkNown Source)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.support.v4.app.FragmentManagerImpl.execPendingActions(UnkNown Source)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.support.v4.app.FragmentManagerImpl.run(UnkNown Source)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.os.Handler.handleCallback(Handler.java:725)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.os.Handler.dispatchMessage(Handler.java:92)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.os.Looper.loop(Looper.java:137)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at androID.app.ActivityThread.main(ActivityThread.java:5039)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at java.lang.reflect.Method.invokeNative(Native Method)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at java.lang.reflect.Method.invoke(Method.java:511)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:560)12-04 03:28:02.228: E/AndroIDRuntime(14466):    at dalvik.system.NativeStart.main(Native Method)

问题是什么.我知道MapVIEw不能从片段中膨胀.但我使用这种技术:
http://xrigau.wordpress.com/2012/03/22/howto-actionbarsherlock-mapfragment-listfragment/

但这仍然不起作用.我需要一些帮助.

解决方法 就在几天前,Google推出了Map API 2.它包含了MapFragment.所以现在你不需要这样的钩子.
https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment 总结

以上是内存溢出为你收集整理的Android地图视图错误:您只能在MapActivity中拥有一个MapView全部内容,希望文章能够帮你解决Android地图视图错误:您只能在MapActivity中拥有一个MapView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1140779.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存