使用google map v2对片段进行充气时出现异常

时间:2013-11-25 21:36:37

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

我有这个片段:

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;。 exeption消息是android.view.InflateException: Binary XML file line #18: Error inflating class fragment。有什么问题?

1 个答案:

答案 0 :(得分:2)

从上一个问题开始,您遇到类似的问题"com.google.android.gms.maps.SupportMapFragment"需要com.google.android.gms.maps.MapFragment,因为您不再使用SupportMapFragment并使用MapFragment

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