我用的版本2.4.0-alpha04
方便使用multi-backstack
的 navigation
. (develop docs)
但我收到以下错误:
Class 'ActionDialogToWriteRoutine' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections
我首先在这里搜索以修复错误,并发现具有相同错误的问题。 (here)我在该链接中看到了一个答案,说该错误已从
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'
}
关于android - 类 'action' 不是抽象的,没有实现抽象成员 public abstract val actionId : Int defined in androidx. navigation.NavDirections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68596264/