2013-11-25 42 views
0

我有這個片段時,膨脹片段:異常與谷歌地圖V2

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 inflating class fragment。哪裏不對?

回答

2

從你最後一個問題,你繼續有類似的問題"com.google.android.gms.maps.SupportMapFragment"必須com.google.android.gms.maps.MapFragment,因爲你不再使用SupportMapFragment和使用MapFragment

再加上你的片段需要延續MapFragmentFragment