我有这个片段:
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
。有什么问题?
答案 0 :(得分:2)
从上一个问题开始,您遇到类似的问题"com.google.android.gms.maps.SupportMapFragment"
需要com.google.android.gms.maps.MapFragment
,因为您不再使用SupportMapFragment并使用MapFragment
加上您的片段需要扩展MapFragment
而不是Fragment