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

标签 java android google-maps android-layout android-fragments

我有这个 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/

相关文章:

ios - TouchableOpacity 在 React Native 的 MapView 中表现得很奇怪

java - 如何交换两个物体的颜色

java - 是否有必要将此 java 程序分为两类?

java - 使用直接调用查询更新表出错

java - 如何让 fragment A 知道 fragment B 中的按钮已按下

android - 如何从android中的另一个应用程序启动一个应用程序?

android - 如何在 Flutter 中让 Android 状态栏变亮

android - 如何在多段线路径上为 google map v2 标记设置动画?

java.net.ConnectException : Connection refused apache mysql

android - Google Maps iOs SDK - 中国