У меня обычно нет проблем при переходе от одного фрагмента к другому фрагменту с помощью кода ниже:
val login = AuthenticationFragmentDirections.actionToLogin()
Navigation.findNavController(fragmentView).navigate(login)
приложение ранее работало хорошо, но почему-то оно больше не работает и выдает ошибку:
androidx.fragment.app.Fragment $ InstantiationException: Невозможно создать экземпляр фрагмента com.muchammadagunglaksana.km.Fragments.Authentication.LoginUsingEmailFragment: вызов конструктора Fragment вызвал исключение
androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.LoginUsingEmailFragment: calling Fragment constructor caused an exception
at androidx.fragment.app.Fragment.instantiate(Fragment.java:503)
at androidx.navigation.fragment.FragmentNavigator.instantiateFragment(FragmentNavigator.java:184)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:212)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:58)
at androidx.navigation.NavController.navigate(NavController.java:822)
at androidx.navigation.NavController.navigate(NavController.java:807)
at androidx.navigation.NavController.navigate(NavController.java:744)
at androidx.navigation.NavController.navigate(NavController.java:730)
at androidx.navigation.NavController.navigate(NavController.java:862)
at com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.AuthenticationFragment$setUpListeners$1.onClick(AuthenticationFragment.kt:55)
at android.view.View.performClick(View.java:5246)
at android.widget.TextView.performClick(TextView.java:10565)
at android.view.View$PerformClick.run(View.java:21200)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:485)
at androidx.navigation.fragment.FragmentNavigator.instantiateFragment(FragmentNavigator.java:184)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:212)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:58)
at androidx.navigation.NavController.navigate(NavController.java:822)
at androidx.navigation.NavController.navigate(NavController.java:807)
at androidx.navigation.NavController.navigate(NavController.java:744)
at androidx.navigation.NavController.navigate(NavController.java:730)
at androidx.navigation.NavController.navigate(NavController.java:862)
at com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.AuthenticationFragment$setUpListeners$1.onClick(AuthenticationFragment.kt:55)
at android.view.View.performClick(View.java:5246)
at android.widget.TextView.performClick(TextView.java:10565)
at android.view.View$PerformClick.run(View.java:21200)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property mContext has not been initialized
at com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.LoginUsingEmailFragment.<init>(LoginUsingEmailFragment.kt:47)
из аутентификации Я хочу, чтобы пользователь мог выбрать, чтобы войти в систему или зарегистрировать пункт назначения, используя код
toLoginButton.setOnClickListener {
val login = AuthenticationFragmentDirections.actionToLogin()
Navigation.findNavController(fragmentView).navigate(login)
}
toRegisterButton.setOnClickListener {
val register = AuthenticationFragmentDirections.actionToRegister()
Navigation.findNavController(fragmentView).navigate(register)
}
, но я не знаю, почему я получил эту ошибку:
здесь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/main_graph"
app:startDestination="@id/destination_home">
<fragment android:id="@+id/destination_authentication"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.AuthenticationFragment"
tools:layout="@layout/fragment_authentication">
<action android:id="@+id/action_toLogin"
app:destination="@id/destination_loginUsingEmail"/>
<action android:id="@+id/action_toRegister"
app:destination="@id/destination_registerUsingEmail"/>
</fragment>
<fragment android:id="@+id/destination_registerUsingEmail"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.RegisterUsingEmailFragment"
tools:layout="@layout/fragment_register_using_email"/>
<fragment android:id="@+id/destination_welcome"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.WelcomeAndOnBoarding.WelcomeFragment"
tools:layout="@layout/fragment_welcome">
<action android:id="@+id/action_toAuthentication"
app:destination="@id/destination_authentication"/>
</fragment>
<fragment android:id="@+id/destination_change_password"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.ChangePasswordFragment"
tools:layout="@layout/fragment_change_password"/>
<fragment android:id="@+id/destination_loginUsingEmail"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.Authentication.LoginUsingEmailFragment"
tools:layout="@layout/fragment_login_using_email">
<action android:id="@+id/action_toChangePassword"
app:destination="@id/destination_change_password"/>
</fragment>
<fragment android:id="@+id/destination_home" android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.Home.HomeFragment"
tools:layout="@layout/fragment_home"/>
<action android:id="@+id/action_global_homeFragment" app:destination="@id/destination_home"/>
<fragment android:id="@+id/destination_create_event"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.CreateEvent.CreateEventFragment"
tools:layout="@layout/fragment_create_event"/>
<fragment android:id="@+id/destination_user_control"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.UserControl.UserControlFragment"
tools:layout="@layout/fragment_profile"/>
<fragment android:id="@+id/destination_search" android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.Search.SearchFragment"
tools:layout="@layout/fragment_search"/>
<fragment android:id="@+id/destination_choose_user_location"
android:name="com.muchammadagunglaksana.kumpul_muslim.Fragments.Reusable.ChooseUserLocationFragment"
tools:layout="@layout/fragment_choose_user_location"/>
<action android:id="@+id/action_global_chooseUserLocationFragment" app:destination="@id/destination_choose_user_location"/><action android:id="@+id/action_global_destination_welcome" app:destination="@id/destination_welcome"/>
действительно нужна ваша помощь, так как я новичок в использовании компонента навигации