приложение вылетает при надувании второго хоста навигации - PullRequest
0 голосов
/ 12 февраля 2020
Приложение

аварийно завершает работу при запуске нового действия с хостом навигации. поэтому мое приложение содержит две операции с графом навигации и хостом навигации, при попытке раздувать второй хост навигации происходит сбой моего приложения. Кажется, я не могу найти какую-либо справку в Интернете об использовании нескольких действий с хостом навигации каждый

log:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.vois, PID: 22503
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vois/com.example.vois.register.RegisterActivity}: android.view.InflateException: Binary XML file line #9 in com.example.vois:layout/activity_register: Binary XML file line #9 in com.example.vois:layout/activity_register: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3447)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7762)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
     Caused by: android.view.InflateException: Binary XML file line #9 in com.example.vois:layout/activity_register: Binary XML file line #9 in com.example.vois:layout/activity_register: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #9 in com.example.vois:layout/activity_register: Error inflating class fragment
     Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.vois.register.WelcomeFragment: calling Fragment constructor caused an exception
        at androidx.fragment.app.Fragment.instantiate(Fragment.java:541)
        at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
        at androidx.fragment.app.FragmentManagerImpl$6.instantiate(FragmentManagerImpl.java:2851)
        at androidx.navigation.fragment.FragmentNavigator.instantiateFragment(FragmentNavigator.java:132)
        at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:162)
        at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:58)
        at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:71)
        at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:28)
        at androidx.navigation.NavController.navigate(NavController.java:859)
        at androidx.navigation.NavController.onGraphCreated(NavController.java:503)
        at androidx.navigation.NavController.setGraph(NavController.java:460)
        at androidx.navigation.NavController.setGraph(NavController.java:425)
        at androidx.navigation.NavController.setGraph(NavController.java:407)
        at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:236)
        at androidx.fragment.app.Fragment.performCreate(Fragment.java:2586)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:838)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1133)
        at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1393)
        at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3205)
        at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
        at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
        at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.vois.register.RegisterActivity.onCreate(RegisterActivity.kt:40)
        at android.app.Activity.performCreate(Activity.java:7981)
        at android.app.Activity.performCreate(Activity.java:7970)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7762)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at androidx.fragment.app.Fragment.instantiate(Fragment.java:523)
            ... 47 more
     Caused by: kotlin.TypeCastException: null cannot be cast to non-null type com.example.vois.register.RegisterActivity
        at com.example.vois.register.WelcomeFragment.<init>(WelcomeFragment.kt:44)
            ... 50 more

основной график навигации:

<?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/navigation"
    app:startDestination="@id/contactsFragment">
.......
</navigation>

хост основной навигации по активности:

<fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/toolbar"
            app:navGraph="@navigation/navigation" />

график навигации по регистру активности:

<?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/navigation_register"
    app:startDestination="@id/welcomeFragment">

    <fragment
        android:id="@+id/welcomeFragment"
        android:name="com.example.vois.register.WelcomeFragment"
        android:label="fragment_welcome"
        tools:layout="@layout/fragment_welcome" >
        <action
            android:id="@+id/action_welcomeFragment_to_profileImageFragment"
            app:destination="@id/profileImageFragment" />
    </fragment>
    <fragment
        android:id="@+id/profileImageFragment"
        android:name="com.example.vois.register.ProfileImageFragment"
        android:label="fragment_profile_image"
        tools:layout="@layout/fragment_profile_image" >
        <action
            android:id="@+id/action_profileImageFragment_to_privacySettingsFragment"
            app:destination="@id/privacySettingsFragment" />
    </fragment>
    <fragment
        android:id="@+id/privacySettingsFragment"
        android:name="com.example.vois.register.PrivacySettingsFragment"
        android:label="fragment_privacy_settings"
        tools:layout="@layout/fragment_privacy_settings" />
</navigation>

хост по регистру активности:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true">


    <fragment
        android:id="@+id/nav_host_fragment_register"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/navigation_register" />



</androidx.constraintlayout.widget.ConstraintLayout>

как запустить второе действие с помощью навигации хост:

val intent = Intent(this, RegisterActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK.or(Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(intent)
            this.finish()

1 Ответ

0 голосов
/ 12 февраля 2020

В соответствии с сообщением об ошибке

Двоичная XML строка файла № 9 в com.example.vois: layout / activity_register: Ошибка надувания фрагмента класса

есть что-то не так с вашим макетом activity_register, но так как мы не знаем, кто из них выложил, вам трудно помочь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...