15

I created a global action with the Android Navigation Component and I'm getting the following error when compiling the code

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/homeEnumerationFragment">

<fragment
    android:id="@+id/homeEnumerationFragment"
    android:name="org.southasia.ghru.ui.homeenumeration.HomeEnumerationFragment"
    android:label="HomeEnumerationFragment"
    tools:layout="@layout/home_enumeration_fragment"></fragment>


<fragment
    android:id="@+id/stationFragments"
    android:name="org.southasia.ghru.ui.station.StationFragment"
    android:label="StationFragment"
    tools:layout="@layout/station_fragment"/>

<fragment
    android:id="@+id/devicesFragment"
    android:name="org.southasia.ghru.ui.devices.DevicesFragment"
    android:label="DevicesFragment"
    tools:layout="@layout/devices_fragment"/>
<action android:id="@+id/action_global_stationFragments3" app:destination="@+id/stationFragments"/>

The error:

Error: Destination with arguments or actions must have 'name' or 'id' attributes.
Max
  • 739
  • 2
  • 8
  • 23
Shanuka
  • 309
  • 1
  • 9

1 Answers1

30

To use global action you need to have an id for your navigation graph (currently it is not generated automatically). Just add 'id' attribute to your navigation element, like this:

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   app:startDestination="@id/homeEnumerationFragment"
   android:id="@+id/main">
Alex
  • 9,102
  • 3
  • 31
  • 35