Class 'action' 不是抽象的,没有实现抽象成员 public abstract val actionId: Int defined in androidx.navigation.NavDirections
Class 'action' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections
我用的是版本2.4.0-alpha04
,方便使用navigation
的multi-backstack
。 (develop docs)
但是我得到以下错误:
Class 'ActionDialogToWriteRoutine' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections
我首先在这里搜索修复错误,发现同样错误的问题。 ()
我在 link 中看到一个答案,说从 v2.4.0-alpha02
开始的错误已修复。
但我仍然得到同样的错误。
所以我根据自己的情况重新发帖
发生了什么事?
build.gradle[app]
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
// safe args
id 'androidx.navigation.safeargs.kotlin'
}
dependencies {
def lifecycle_version = "2.3.1"
def nav_version = "2.4.0-alpha04"
// AAC
implementation("androidx.fragment:fragment-ktx:1.3.4")
// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
}
nav_graph.xml
<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"
android:id="@+id/nav_graph"
app:startDestination="@id/calendar">
<include app:graph="@navigation/calendar"/>
<include app:graph="@navigation/list"/>
<include app:graph="@navigation/write_home"/>
</navigation>
write_home.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:id="@+id/write"
app:startDestination="@id/home">
<fragment
android:id="@+id/home"
android:name="com.example.writeweight.fragment.WriteRoutineHomeFragment"
android:label="fragment_write_routine_home"
tools:layout="@layout/fragment_write_routine_home" >
<action
android:id="@+id/action_home_to_dialog"
app:destination="@id/dialog" />
</fragment>
<fragment
android:id="@+id/dialog"
android:name="com.example.writeweight.fragment.BodyPartDialogFragment"
android:label="BodyPartDialogFragment"
tools:layout="@layout/fragment_body_part_dialog">
<action
android:id="@+id/action_dialog_to_write_routine"
app:destination="@id/write_routine" />
</fragment>
<fragment
android:id="@+id/write_routine"
android:name="com.example.writeweight.fragment.WriteRoutineFragment"
android:label="WriteRoutineFragment"
tools:layout="@layout/fragment_writing_routine">
<argument
android:name="title"
app:argType="string"
app:nullable="true"
android:defaultValue="@null"/>
<argument
android:name="workout"
app:argType="string"
app:nullable="true"
android:defaultValue="@null"/>
<action
android:id="@+id/action_write_routine_to_workout_tab"
app:destination="@id/workout_tab" />
</fragment>
<fragment
android:id="@+id/workout_tab"
android:name="com.example.writeweight.fragment.WorkoutListTabFragment"
android:label="WorkoutListTabFragment"
tools:layout="@layout/fragment_workout_list_tab">
<action
android:id="@+id/action_workout_tab_to_write_routine"
app:destination="@id/write_routine" />
</fragment>
</navigation>
在您的应用级别 build.gradle 文件替换
plugins {
id 'androidx.navigation.safeargs.kotlin'
}
和
plugins {
id 'androidx.navigation.safeargs'
}
在您的 build.gradle 文件(模块)中。
改变
plugin{
....
id 'androidx.navigation.safeargs.kotlin'
}
到
plugin{
.....
id 'androidx.navigation.safeargs'
}
我用的是版本2.4.0-alpha04
,方便使用navigation
的multi-backstack
。 (develop docs)
但是我得到以下错误:
Class 'ActionDialogToWriteRoutine' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections
我首先在这里搜索修复错误,发现同样错误的问题。 (
我在 link 中看到一个答案,说从 v2.4.0-alpha02
开始的错误已修复。
但我仍然得到同样的错误。
所以我根据自己的情况重新发帖
发生了什么事?
build.gradle[app]
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
// safe args
id 'androidx.navigation.safeargs.kotlin'
}
dependencies {
def lifecycle_version = "2.3.1"
def nav_version = "2.4.0-alpha04"
// AAC
implementation("androidx.fragment:fragment-ktx:1.3.4")
// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
}
nav_graph.xml
<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"
android:id="@+id/nav_graph"
app:startDestination="@id/calendar">
<include app:graph="@navigation/calendar"/>
<include app:graph="@navigation/list"/>
<include app:graph="@navigation/write_home"/>
</navigation>
write_home.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:id="@+id/write"
app:startDestination="@id/home">
<fragment
android:id="@+id/home"
android:name="com.example.writeweight.fragment.WriteRoutineHomeFragment"
android:label="fragment_write_routine_home"
tools:layout="@layout/fragment_write_routine_home" >
<action
android:id="@+id/action_home_to_dialog"
app:destination="@id/dialog" />
</fragment>
<fragment
android:id="@+id/dialog"
android:name="com.example.writeweight.fragment.BodyPartDialogFragment"
android:label="BodyPartDialogFragment"
tools:layout="@layout/fragment_body_part_dialog">
<action
android:id="@+id/action_dialog_to_write_routine"
app:destination="@id/write_routine" />
</fragment>
<fragment
android:id="@+id/write_routine"
android:name="com.example.writeweight.fragment.WriteRoutineFragment"
android:label="WriteRoutineFragment"
tools:layout="@layout/fragment_writing_routine">
<argument
android:name="title"
app:argType="string"
app:nullable="true"
android:defaultValue="@null"/>
<argument
android:name="workout"
app:argType="string"
app:nullable="true"
android:defaultValue="@null"/>
<action
android:id="@+id/action_write_routine_to_workout_tab"
app:destination="@id/workout_tab" />
</fragment>
<fragment
android:id="@+id/workout_tab"
android:name="com.example.writeweight.fragment.WorkoutListTabFragment"
android:label="WorkoutListTabFragment"
tools:layout="@layout/fragment_workout_list_tab">
<action
android:id="@+id/action_workout_tab_to_write_routine"
app:destination="@id/write_routine" />
</fragment>
</navigation>
在您的应用级别 build.gradle 文件替换
plugins {
id 'androidx.navigation.safeargs.kotlin'
}
和
plugins {
id 'androidx.navigation.safeargs'
}
在您的 build.gradle 文件(模块)中。
改变
plugin{
....
id 'androidx.navigation.safeargs.kotlin'
}
到
plugin{
.....
id 'androidx.navigation.safeargs'
}