有一个问题与方向变化的GoogleMap V2应用程序崩溃 [英] Having an issue with GoogleMap v2 crashing app on orientation change

查看:282
本文介绍了有一个问题与方向变化的GoogleMap V2应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在处理这个问题了一段时间。我用这个问题作为一个参考:
<一href=\"http://stackoverflow.com/questions/13721929/using-actionbarsherlock-with-the-new-supportmapfragment\">Using ActionBarSherlock随着新SupportMapFragment

I've been dealing with this problem for a while now. I used this question as a reference: Using ActionBarSherlock With the New SupportMapFragment

我目前使用ActionBarSherlock和我使用VIPUL沙阿的,而简单的实现地图的。它出色的作品,到底做什么,我需要它。然而,在方向改变,整个应用程序崩溃。这是我的日志:

I'm currently using ActionBarSherlock and I'm using Vipul Shah's rather simple implementation of a map. It works brilliantly, does exactly what I need it to. However, on Orientation change, the entire app crashes. Here is my log:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.meetball_1/com.meetball_1.HomeActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3740)
    at android.app.ActivityThread.access$700(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
    at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:133)
    at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:261)
    at com.meetball_1.HomeActivity.onCreate(HomeActivity.java:70)
    at android.app.Activity.performCreate(Activity.java:5133)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
    ... 12 more
    Caused by: java.lang.IllegalStateException: Fragment com.google.android.gms.maps.SupportMapFragment did not create a view.
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:303)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
    ... 24 more

我认识到,无论出于何种原因没有被创建视图和误差来自于应用程序不能夸大我的课片段。如何因为我觉得实现地图很简单,所以应该是我的解决方案我解决这个问题,而不使事情太复杂了。这里是我的XML片段:

I realize that for whatever reason a view is not being created and that the error comes from the app failing to inflate my class fragment. How do I fix this without making things too complicated because I feel that implementing the map was simple so should be my solution. here is my xml snippet:

<fragment android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="230dp"
    android:layout_weight="1"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_gravity="center_horizontal|top" />

下面是我的相关code片断:

Here is my relevant code snippet:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

 SupportMapFragment fragment = SupportMapFragment.newInstance();
        getSupportFragmentManager().beginTransaction()
                .add(R.id.map, fragment).commit();
}

感谢大家提前!

我试图在这一点上的一切。这与GoogleMap的一个bug?如何解决呢?

I've tried everything at this point. Is this a bug with Googlemap? How do I fix it?

推荐答案

我有同样的问题,解决这个问题,我不得不用,而不是片段的FrameLayout:

I had the same problem and to solve it, I had to use FrameLayout instead of fragment:

<FrameLayout
        android:id="@+id/mapview"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

和则:

SupportMapFragment mMapFragment = (SupportMapFragment) getActivity()
            .getSupportFragmentManager().findFragmentById(R.id.mapview);

    if (mMapFragment == null) {
        mMapFragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(R.id.mapview, mMapFragment).commit();
    }

这篇关于有一个问题与方向变化的GoogleMap V2应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆