Skip to content

null cannot be cast to non-null type com.reactnativenavigation.NavigationActivity #8048

Closed
@AleshkovDenis

Description

@AleshkovDenis

What happened?

How can I fix it?

Image

What was the expected behaviour?

No response

Was it tested on latest react-native-navigation?

  • I have tested this issue on the latest react-native-navigation release and it still reproduces.

Help us reproduce this issue!

MainAcitivity.kt

package com.app;

import com.reactnativenavigation.NavigationActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled;
import com.facebook.react.defaults.DefaultReactActivityDelegate;

class MainActivity:NavigationActivity() {}

MainApplication.kt

package com.app

import com.facebook.react.PackageList
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.reactnativenavigation.NavigationApplication
import com.reactnativenavigation.react.NavigationPackage
import com.reactnativenavigation.react.NavigationReactNativeHost
import com.microsoft.codepush.react.CodePush

class MainApplication : NavigationApplication() {
  override val reactNativeHost: ReactNativeHost =
      object : NavigationReactNativeHost(this) {
        override fun getPackages(): List<ReactPackage> =
            PackageList(this).packages.apply {
              // Packages that cannot be autolinked yet can be added manually here, for example:
              // add(MyReactNativePackage())
            }

        override fun getJSMainModuleName(): String = "index"

        override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

        override fun getJSBundleFile(): String {
          return CodePush.getJSBundleFile() 
        }

        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
      }

      override val reactHost: ReactHost
          get() = getDefaultReactHost(this, reactNativeHost)

  override fun onCreate() {
    super.onCreate()
  }
}

In what environment did this happen?

React Native Navigation version: 8.1.0
React Native version: 0.77.2
Has Fabric (React Native's new rendering system) enabled: yes
Node version: 20
Device model: Samsung Galaxy Tab A9 + (emulator)
Android version: 15

Activity

ortweinl

ortweinl commented on Jun 17, 2025

@ortweinl

Hey @AleshkovDenis,

did you try to add RNNotificationsPackage in getPackages?

 override fun getPackages(): List<ReactPackage> =
                        PackageList(this).packages.apply {
                            add(NavigationPackage()) // <-- 
                        }

Android works for me with this MainApplication.kt

package ...

import com.facebook.react.PackageList
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.reactnativenavigation.NavigationApplication
import com.reactnativenavigation.RNNToggles
import com.reactnativenavigation.react.NavigationPackage
import com.reactnativenavigation.react.NavigationReactNativeHost
import com.wix.reactnativenotifications.RNNotificationsPackage;

class MainApplication :
        NavigationApplication(
                mapOf(
                        RNNToggles.TOP_BAR_COLOR_ANIMATION__PUSH to true,
                        RNNToggles.TOP_BAR_COLOR_ANIMATION__TABS to true
                ) 
        ) {

    override val reactNativeHost: ReactNativeHost =
            object : NavigationReactNativeHost(this) {

                override fun getJSMainModuleName(): String = "index"

                override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

                override fun getPackages(): List<ReactPackage> =
                        PackageList(this).packages.apply {
                            add(NavigationPackage())
                        }

                override val isHermesEnabled: Boolean
                    get() = BuildConfig.IS_HERMES_ENABLED

                override val isNewArchEnabled: Boolean
                    get() = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
            }

    override val reactHost: ReactHost
        get() = getDefaultReactHost(this, reactNativeHost)

    override fun onCreate() {
        super.onCreate()
    }
}


and this MainActivity.kt:

package ...

import android.os.Bundle
import com.reactnativenavigation.NavigationActivity

class MainActivity : NavigationActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
  }
}
AleshkovDenis

AleshkovDenis commented on Jun 17, 2025

@AleshkovDenis
Author

@ortweinl it didn't help

AleshkovDenis

AleshkovDenis commented on Jun 20, 2025

@AleshkovDenis
Author

resolved

danilomsou

danilomsou commented on Jun 30, 2025

@danilomsou

@AleshkovDenis How did you solve it? I have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @danilomsou@ortweinl@AleshkovDenis

        Issue actions

          null cannot be cast to non-null type com.reactnativenavigation.NavigationActivity · Issue #8048 · wix/react-native-navigation