java.lang.ClassCastException:android.support.v4.app.NoSaveStateFrameLayout不能转换为com.google.android.maps.MapView [英] java.lang.ClassCastException: android.support.v4.app.NoSaveStateFrameLayout cannot be cast to com.google.android.maps.MapView

查看:386
本文介绍了java.lang.ClassCastException:android.support.v4.app.NoSaveStateFrameLayout不能转换为com.google.android.maps.MapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的活动code

Here is my activity code

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
    GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    mapView = (MapView) findViewById(R.id.map);

GoogleMap map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map))
        .getMap();
}

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.id.map, container, false);
}

这是我的LogCat中

and this is my LogCat

03-22 11:53:38.497: E/AndroidRuntime(436): FATAL EXCEPTION: main
03-22 11:53:38.497: E/AndroidRuntime(436): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alltaskass/com.example.alltaskass.Map}: java.lang.ClassCastException: android.support.v4.app.NoSaveStateFrameLayout cannot be cast to com.google.android.maps.MapView
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.app.ActivityThread.access$1500(ActivityThread.java:123)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.os.Looper.loop(Looper.java:126)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.app.ActivityThread.main(ActivityThread.java:3997)
03-22 11:53:38.497: E/AndroidRuntime(436):  at java.lang.reflect.Method.invokeNative(Native Method)
03-22 11:53:38.497: E/AndroidRuntime(436):  at java.lang.reflect.Method.invoke(Method.java:491)
03-22 11:53:38.497: E/AndroidRuntime(436):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-22 11:53:38.497: E/AndroidRuntime(436):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-22 11:53:38.497: E/AndroidRuntime(436):  at dalvik.system.NativeStart.main(Native Method)
03-22 11:53:38.497: E/AndroidRuntime(436): Caused by: java.lang.ClassCastException: android.support.v4.app.NoSaveStateFrameLayout cannot be cast to com.google.android.maps.MapView
03-22 11:53:38.497: E/AndroidRuntime(436):  at com.example.alltaskass.Map.onCreate(Map.java:35)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
03-22 11:53:38.497: E/AndroidRuntime(436):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
03-22 11:53:38.497: E/AndroidRuntime(436):  ... 11 more

我alredy访问<一个href=\"http://stackoverflow.com/questions/9440606/mapview-inside-fragment-specified-child-already-has-a-parent\">this和解决方案,但我仍然是不能够解决我的问题,请给我一些解决方案。
谢谢

I alredy visited this and this solution but still I am not able to solve my problem, Please give me some solution. Thank you

推荐答案

我不明白你的code:

I can't understand your code:


  1. 您首先试图获得图形页面

mapView = (MapView) findViewById(R.id.map);


  • 然后你试图让 SupportMapFragment

    GoogleMap map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    


  • 从相同的用户界面元素: R.id.map

    from the same UI element: R.id.map

    图形页面是一个谷歌地图 API V1 元素和 SupportMapFragment API V2

    While MapView is a Google Map API V1 element and the SupportMapFragment is from API V2.

    什么是你在 R.layout.map 布局使用?我们展示了它的code。

    What are you using in the R.layout.map layout? show us it's code.

    如果你想使用API​​ V2,这里博客文章中,我就如何地图应用程序中集成写道:

    if you want to use API V2, here a blog post I wrote on how to integrate a map in your application:

    谷歌地图API V2

    这篇关于java.lang.ClassCastException:android.support.v4.app.NoSaveStateFrameLayout不能转换为com.google.android.maps.MapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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