For the second day I’m trying to screw the google map, but everything is even. Basically, I took info from google documentation. I also tried other ways to solve this problem.

When building the application, the same error constantly goes out and for some reason always refers to the line where I initialized binding binding = DataBindingUtil.setContentView (this, R.layout.activity_screen_map);

I ask for help from more experienced colleagues.

A piece of typesetting with a fragment

<fragment android:id="@+id/mapView" class="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/toolbar" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" style="@style/toolbar"/> </android.support.constraint.ConstraintLayout> 

The implementation class itself:

private SupportMapFragment mapFragment; private GoogleMap googleMap;

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_screen_map); //Getting an instance binding = DataBindingUtil.setContentView(this, R.layout.activity_screen_map); googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); googleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions) .build(); mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView); mapFragment.getMapAsync(this); //Call the toolbar setSupportActionBar(binding.toolbar); binding.toolbar.setTitle(getResources().getString(R.string.mapTitle)); } @Override public void onMapReady(GoogleMap gMap) { googleMap = gMap; LatLng sydney = new LatLng(-33.852, 151.211); googleMap.addMarker(new MarkerOptions().position(sydney) .title("Marker in Sydney")); googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); } 

Manifesto:

 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" /> <activity android:name=".MainActivity" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ScreenMapActivity" android:screenOrientation="portrait"/> <activity android:name=".ScreenFamilyActivity" android:label="@string/contacts" android:launchMode="singleTop" android:screenOrientation="portrait" android:parentActivityName=".ScreenMapActivity"/> <activity android:name=".AddContactActivity" android:label="@string/addContact"></activity> </application> 

All the necessary dependencies are connected.

The error itself:

android.view.InflateException: Binary XML file line # 11: Error inflating class fragment

11 line, this is just the line where the fragment begins. Already the whole head broke itself.

Also here is the following Binary XML file line # 11 error: Duplicate id 0x7f08006e, tag null, or parent id 0xffffffff for com.google.android.gms.maps.SupportMapFragment

It says that two identical id. I checked everything and found nothing.

I ask you not to throw stones, I just started studying android for a long time and I need real help.

  • Put another id for the fragment - Flippy
  • @Flippy Tried to change the id, did not help - Dmitrii Tretiakov
  • And try MapView instead of a fragment - Flippy
  • @Flippy Is mapView not limited in functionality? I need to fully use the map in the application. Track other users, etc - Dmitrii Tretiakov
  • one
    Somehow it was not possible to get acquainted with DataBinding , but the logic and the signature of DataBindingUtil.setContentView(...) should be used instead of Activity.setContentView(...) - then you call the second inflate of the markup because of the call of both and the second one falls into FragmentManager an instance of a map fragment, respectively, with identical id and tag . - woesss

1 answer 1

Problem solved. I tried to use MapView before, but a little differently. Yesterday I revised this approach and decided to try again.

In general, the code below.

 Bundle mapViewBundle = null; if (savedInstanceState != null) { mapViewBundle = savedInstanceState.getBundle(MAP_VIEW_BUNDLE_KEY); } mapView = binding.mapV; mapView.onCreate(mapViewBundle); mapView.getMapAsync(this); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Bundle mapViewBundle = outState.getBundle(MAP_VIEW_BUNDLE_KEY); if (mapViewBundle == null) { mapViewBundle = new Bundle(); outState.putBundle(MAP_VIEW_BUNDLE_KEY, mapViewBundle); } mapView.onSaveInstanceState(mapViewBundle); } @Override protected void onResume() { super.onResume(); mapView.onResume(); } @Override protected void onStart() { super.onStart(); mapView.onStart(); } @Override protected void onStop() { super.onStop(); mapView.onStop(); } @Override protected void onPause() { mapView.onPause(); super.onPause(); } @Override protected void onDestroy() { mapView.onDestroy(); super.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); } @Override public void onMapReady(GoogleMap googleMap) { gmap = googleMap; gmap.setMinZoomPreference(12); LatLng ny = new LatLng(40.7143528, -74.0059731); gmap.moveCamera(CameraUpdateFactory.newLatLng(ny)); } 

Yes, and be sure to promapit the entire life cycle of activation.

On account of the past error, if someone meets a similar one and does not understand why it occurs.

As @woesss wrote in the comments. I used DataBinding in my work. Because of the inclusion in the activity fragment, a controversial situation occurred. As I understand. Banding himself created a fragment, then he tried to infect the fragment itself with a map, and because of this, the error Duplicate id appeared. Maybe I'm wrong.