gpt4 book ai didi

java - 使用谷歌地图 v2 膨胀 fragment 时出现异常

转载 作者:行者123 更新时间:2023-12-02 06:29:30 24 4
gpt4 key购买 nike

我有这个 fragment :

import android.app.Fragment;
public class MapsFragment extends Fragment
{
View rootView;
GoogleMap map;

AutoCompleteTextView addressInput;
ProgressDialog progressDialog;

FindMapLocationTask findMapLocationTask;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if (rootView != null)
{
ViewGroup parent = (ViewGroup) rootView.getParent();
if (parent != null)
parent.removeView(rootView);
}
try
{
rootView = inflater.inflate(R.layout.map_frag, container, false);
}
catch (InflateException e)
{
return rootView;
}
...

这是map_frag.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<AutoCompleteTextView
android:id="@+id/map_frag_location_AutoCompleteTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10" >

<requestFocus />
</AutoCompleteTextView>

<fragment
android:id="@+id/map_frag_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/map_frag_location_AutoCompleteTextView"
android:layout_alignParentLeft="true"
class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

我遇到异常并陷入了这个陷阱:return rootView;。异常消息为 android.view.InflateException: Binary XML file line #18: Error inflateing classfragment。出了什么问题?

最佳答案

继续上一个问题,您遇到了类似的问题“com.google.android.gms.maps.SupportMapFragment”需要是com.google.android.gms.maps.MapFragment 因为您不再使用 SupportMapFragment 并使用 MapFragment

加上您的 fragment 需要扩展MapFragment而不是Fragment

关于java - 使用谷歌地图 v2 膨胀 fragment 时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20203854/

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