简体   繁体   English

Android Google Map InflateException:二进制XML文件第13行

[英]Android Google Map InflateException: Binary XML file line #13

In my activity_main.XML file I have three main parts, 1) ActionBar(ToolBar) - Its in the top, 2) FrameLayout - in the middle, 3) BottomBar(ToolBar). 在我的activity_main.XML文件中,我分为三个主要部分:1)ActionBar(ToolBar)-位于顶部,2)FrameLayout-位于中间,3)BottomBar(ToolBar)。

Now in FrameLayout I want to add and replace fragment based upon the button selection made in bottom toolbar. 现在在FrameLayout中,我要根据底部工具栏中的按钮选择添加和替换片段。 In my first fragment I am having google map and in my 2nd and 3rd fragment I am having ListView. 在我的第一个片段中,我有google map,在我的第二个和第三个片段中,我有ListView。 I also adding the fragment in the backstack by adding this while replacing/adding fragment 我还通过在替换/添加片段的同时添加片段的方式在后堆栈中添加了片段

ft.addToBackStack(null);

Now the problem is, whenever I open each fragment by clicking the bottom bar buttons all the fragment are working fine completely. 现在的问题是,每当我通过单击底部的栏按钮打开每个片段时,所有片段都可以正常工作。 But if I open 2nd or 3rd fragment from 1st(Google Map) fragment, and If I again try to comeback to the same Google Map fragment by clicking the back button Its showing these errors in Logcat. 但是,如果我从1st(Google Map)片段中打开了2nd或3rd片段,并且如果我再次尝试通过单击“后退”按钮返回相同的Google Map片段,它在Logcat中显示了这些错误。

Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f0e00d9, tag null, or parent id 0xffffffff wi
09-16 16:46:29.112    6985-6985/com.imnv.im026.goodmorning E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.imnv.im026.goodmorning, PID: 6985
android.view.InflateException: Binary XML file line #8: Error inflating class fragment
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
     ........................   com.imnv.im026.goodmorning.FragmentLocate.onCreateView(FragmentLocate.java:64)

And my map fragment xml file is 我的地图片段xml文件是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">

<fragment
    android:id="@+id/locateDriverMap"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:id="@+id/locateCallIconLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical">

    <include
        android:id="@+id/includedCallIcon"
        layout="@layout/locate_frament_bottom_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>

Any my map fragment class is... 我的任何地图片段类是...

public class FragmentLocate extends Fragment {

private PrefManager pref;
ur="example.com/---";
private GoogleMap mMap;
Activity mActivity;
private View view;
private String userId, driverId;
private static double latitude1, longitude1;

android.support.v4.app.FragmentManager fragmentManager;

GetDriverForCustomer getDriverId;

public FragmentLocate() {
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    this.mActivity = activity;
}

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

    view = inflater.inflate(R.layout.fragment_locate, container, false);

    getDriverId = new GetDriverForCustomer(getActivity());
    driverId = getDriverId.getDriverProfileDetails();

    pref = new PrefManager(getActivity());
    userId = pref.getKeyUserid();

    getDriverGeoLocation();
         mMap =   ((SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map))
            .getMap();


    mMap.setOnMyLocationChangeListener(myLocationChangeListener);
    return view;
}

@Override
public void onStart() {
    super.onStart();

}

private GoogleMap.OnMyLocationChangeListener myLocationChangeListener =  new GoogleMap.OnMyLocationChangeListener() {
    @Override
    public void onMyLocationChange(Location location) {
        LatLng loc = new LatLng(location.getLatitude(), location.getLongitude());

        mMap.addMarker(new MarkerOptions().position(loc).icon(null).title("Your Location"));
        if (mMap != null) {
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f));
        }
    }
};

private void setUpMap() {
    mMap.addMarker(new MarkerOptions().position(new LatLng(latitude1, longitude1)).title("Driver Location").icon(BitmapDescriptorFactory.fromResource(R.drawable.car_marker)));
    LatLng coordinate = new LatLng(latitude1, longitude1);
    CameraUpdate DriverLocation = CameraUpdateFactory
            .newLatLngZoom(coordinate, 12);
    mMap.setMyLocationEnabled(true);
    mMap.animateCamera(DriverLocation);

    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(coordinate)
            .zoom(17)
            .build();
    mMap.animateCamera(CameraUpdateFactory
            .newCameraPosition(cameraPosition));
}

/*@Override
public void onResume() {
    super.onResume();
    *//*setUpMapIfNeeded();
    if (mMap == null) {
        mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map))
                .getMap();
        if (mMap != null) {
            setUpMap();
        }
    }*//*
}*/

public void getDriverGeoLocation() {
    /*driverId = pref.getKeyDriverid();
    Log.d("driverId", driverId);*/

    String fullUrl = locateURL + driverId;
    Log.d("PrintFullURL", fullUrl);

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
            fullUrl, null, new Response.Listener<JSONObject>() {

        private String jsonResponse = "";

        @Override
        public void onResponse(JSONObject response) {

            Log.d("Activity Car Profile ", response.toString());

            try {
                JSONArray jcarArray = response.getJSONArray("getdriverlocation");

                for (int i = 0; i < jcarArray.length(); i++) {
                    JSONObject driverLocation = jcarArray.getJSONObject(i);

                    latitude1 = Double.parseDouble(driverLocation.getString("latitude"));
                    longitude1 = Double.parseDouble(driverLocation.getString("longitude"));
                    Log.e("latitude & longitude", latitude1 + " " + longitude1);
                }

                mMap.addMarker(new MarkerOptions().position(new LatLng(latitude1, longitude1)).title("Marker").icon(BitmapDescriptorFactory.fromResource(R.drawable.car_marker)));
                LatLng coordinate = new LatLng(latitude1, longitude1);
                CameraUpdate DriverLocation = CameraUpdateFactory
                        .newLatLngZoom(coordinate, 12);
                mMap.setMyLocationEnabled(true);
                mMap.animateCamera(DriverLocation);

                CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(coordinate)
                        .zoom(17)
                        .build();
                mMap.animateCamera(CameraUpdateFactory
                        .newCameraPosition(cameraPosition));


            } catch (JSONException e) {
                e.printStackTrace();
                Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
            }


        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d("Activity Car Profile", "Error: " + error.toString());

        }
    });

    AppController.getInstance().addToRequestQueue(jsonObjReq);
}
}

And My Manifestfile is... 我的清单文件是...

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:name=".app.AppController"
    android:allowBackup="true"
    android:icon="@mipmap/gm_icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:uiOptions="splitActionBarWhenNarrow">
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />
    <meta-data
        android:name="android.support.UI_OPTIONS"
        android:value="splitActionBarWhenNarrow" />

    <activity
        android:name=".ViewPagerScreen"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Login"
        android:label="string/login_bt" />
    <activity
        android:name=".DriverShiftActivity"
        android:label="@string/title_activity_driver_shift"
        android:uiOptions="splitActionBarWhenNarrow">
        <meta-data
            android:name="android.support.UI_OPTIONS"
            android:value="splitActionBarWhenNarrow" />
    </activity>
    <activity
        android:name=".BaseMenuActivity"
        android:label="@string/title_activity_base_menu"
        android:uiOptions="splitActionBarWhenNarrow">
        <meta-data
            android:name="android.support.UI_OPTIONS"
            android:value="splitActionBarWhenNarrow" />
    </activity>
    <activity
        android:name=".SignUp"
        android:label="@string/title_activity_sign_up" />
    <activity
        android:name=".DiaglogBoxShiftDriver"
        android:label="@string/title_activity_diaglog_box_shift_driver"
        android:theme="@android:style/Theme.Dialog" />
    <activity
        android:name=".FuelDetails"
        android:label="@string/title_activity_fuel_details" />
    <activity
        android:name=".MyProfile"
        android:label="@string/title_activity_my_profile" />
    <activity
        android:name=".CarProfile"
        android:label="@string/title_activity_car_profile" />
    <activity
        android:name=".CustomerProfile"
        android:label="@string/title_activity_customer_profile" />
    <activity
        android:name=".ChatTimeLine"
        android:label="@string/title_activity_chat_time_line" />
    <activity
        android:name=".CustomerActivity"
        android:label="@string/title_activity_customer"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".CustomerEnquiryActivity"
        android:label="@string/title_activity_customer_enquiry"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".CustomerEmergencyActivity"
        android:label="@string/title_activity_customer_emergency"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".CustomerMyProfile"
        android:label="@string/title_activity_customer_my_profile"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".CustomerDriverProfile"
        android:label="@string/title_activity_customer_driver_profile"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".CustomerPlaceInDetail"
        android:label="@string/title_activity_customer_place_in_detail"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".CustomerSelectedCategory"
        android:label="@string/title_activity_customer_selected_category"
        android:theme="@style/MyMaterialTheme" />
    <activity
        android:name=".CustomerChangePassword"
        android:label="@string/title_activity_customer_forget_password"
        android:theme="@style/MyMaterialTheme" />
</application>

</manifest>

And I am repeating its showing error only when I try to comeback to the fragment by clicking back button. 而且,仅当我尝试通过单击“后退”按钮返回到片段时,才重复显示错误。 Thank you. 谢谢。

try this code in oncreat 在oncreat上尝试此代码

 if (view != null) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null)
        parent.removeView(view);
}
try {
    view = inflater.inflate(R.layout.map, container, false);
} catch (InflateException e) {
    /* map is already there, just return view as it is */
}


return view;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android谷歌地图错误android.view.InflateException:二进制XML文件行#6:错误启动类片段 - Android Google Map error android.view.InflateException: Binary XML file line #6: error initiating class fragment Android InflateException二进制XML文件第2行 - Android InflateException Binary XML file line #2 android.view.InflateException:二进制XML文件第13行:错误膨胀了类android.widget.TextView - android.view.InflateException: Binary XML file line #13: Error inflating class android.widget.TextView Android-InflateException:二进制XML文件第7行 - Android - InflateException: Binary XML file line #7 android.view.InflateException:二进制XML文件第13行。使用MapFragment时 - android.view.InflateException: Binary XML file line #13..While using MapFragment java.lang.RuntimeException:无法启动活动 android.view.InflateException:二进制 XML 文件行 #13 - java.lang.RuntimeException: Unable to start activity android.view.InflateException: Binary XML file line #13 原因:android.view.InflateException:二进制XML文件行#13:错误夸大了类片段 - Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment android.view.InflateException:二进制XML文件第13行:膨胀类ViewPager的错误 - android.view.InflateException: Binary XML file line #13: Error inflating class ViewPager InflateException:二进制XML文件第7行 - InflateException: Binary XML file line #7 android.view.InflateException:二进制XML文件第22行 - android.view.InflateException: Binary XML file line #22
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM