gpt4 book ai didi

java - 在框架布局中显示 map fragment

转载 作者:行者123 更新时间:2023-12-02 09:13:03 25 4
gpt4 key购买 nike

我尝试在框架布局中显示 map ,但它不断崩溃并出现错误“尝试调用虚拟方法 com.google.android.gms.maps.supportmapfragment”。 getmapasynctask来了。谷歌。安卓。 Gms.maps.onreadycallback 空对象引用'。下面是我的主要 Activity 代码

     private GoogleMap mMap;

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


SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapee);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap=googleMap;
LatLng Kuta=new LatLng(12,28);
mMap.addMarker(new MarkerOptions().position(Kuta).title("kk"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(Kuta));

}

}

我做了研究并发现了这个findFragmentById for SupportMapFragment returns null in Android Studio遗憾的是,该解决方案要求我将 getsupporfragmentmanager 更改为 getchildfragmentmanager,当我尝试此操作时,我收到错误无法解析符号 getchildfragmentmanager。下面是我的 xml

   <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Standardkuta">

<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="120dp"
android:layout_marginRight="120dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

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

请帮忙

最佳答案

尝试使用

android:name="com.google.android.gms.maps.SupportMapFragment"

而不是

android:name="com.google.android.gms.maps.MapFragment"

关于java - 在框架布局中显示 map fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59239195/

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