gpt4 book ai didi

java - 是否可以将 Google Maps V2 MapFragment 放入 ActionBar 选项卡中?

转载 作者:行者123 更新时间:2023-11-30 03:40:20 25 4
gpt4 key购买 nike

我有一个使用操作栏选项卡的应用程序。我正在尝试升级应用程序以使用 Google Maps V2 (MapFragment),但是当 MapFragment 从主要 Activity 传递到 fragment 容器时,它全部崩溃。

map fragment :

public class EstablishmentGoogleMapFragment extends MapFragment {

private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
mMap = getMap();
return root;
}
}

fragment 交易:

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
if(fragment == null){
String fragmentName = fragmentClass.getName();
fragment = Fragment.instantiate(activity, fragmentName);
ft.add(fragmentContainer, fragment, fragmentName);
} else {
ft.attach(fragment);
}
}

日志:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.rb.hellojson/com.rb.hellojson.EstablishmentGoogleMapFragment}:
java.lang.ClassCastException: com.rb.hellojson.EstablishmentGoogleMapFragment cannot be cast to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.rb.hellojson.EstablishmentGoogleMapFragment cannot be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
... 11 more

最佳答案

这个错误应该很清楚:

引起:java.lang.ClassCastException:com.rb.hellojson.EstablishmentGoogleMapFragment cannot be cast to android.app.Activity

你是想在这个 fragment 上做 startActivity 还是什么?

对于以后的修复:mMap = getMap(); 此时将返回 null(或者可能不返回)。

编辑:

有些东西正在启动您的 fragment ,就像它是一项 Activity 一样。而如果不是Launcher,因为fragment是在Manifest中定义的...

关于java - 是否可以将 Google Maps V2 MapFragment 放入 ActionBar 选项卡中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15840995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com