引起:android.view.InflateException:二进制XML文件行#33:错误膨胀类片段

时间:2014-03-22 22:00:26

标签: android inflate-exception

我正在使用滑动菜单。它只运行一次。当我回到片段时,应用程序崩溃了。当我的应用程序启动它将显示谷歌地图但通过滑块导航我改变我的视频。然后当我来到谷歌地图的相同视图时它崩溃了。

这是我的logcat:

03-23 02:53:09.775: E/AndroidRuntime(22559): android.view.InflateException: Binary XML file line #32: Error inflating class fragment 
03-23 02:53:09.775: E/AndroidRuntime(22559):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-23 02:53:09.775: E/AndroidRuntime(22559):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-23 02:53:09.775: E/AndroidRuntime(22559):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-23 02:53:09.775: E/AndroidRuntime(22559):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-23 02:53:09.775: E/AndroidRuntime(22559):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 

这是我的片段:

public class HomeFragment extends Fragment {

// Google Map
private GoogleMap googleMap;


public HomeFragment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.vaccinationmap, container, false);

    try {
        // Loading map
        initilizeMap();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return rootView;
}

/**
 * function to load map. If map is not created it will create it for you
 * */
private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        double latitude = 29.4000;
        double longitude = 69.1833;
        googleMap.getUiSettings().setCompassEnabled(false);
        googleMap.getUiSettings().setMyLocationButtonEnabled(true);
        googleMap.getUiSettings().setRotateGesturesEnabled(true);
        CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(latitude, longitude)).zoom(4).build();
        googleMap.animateCamera(CameraUpdateFactory
                .newCameraPosition(cameraPosition));

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getActivity(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

@Override
public void onDestroyView() {
    super.onDestroyView();
}


}

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >"
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="10" >
    <Button
        android:id="@+id/bMyMap"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:text="My Map" />
    <Button
        android:id="@+id/bGlobal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:text="Global Map" />
</LinearLayout>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>
</LinearLayout>

0 个答案:

没有答案