Skip to content

Android Java.Lang.NullPointerException crash in CarouselViewRenderer.SetNativeView when Context is AndroidX.AppCompat.View.ContextThemeWrapper #3

Description

@vitalii-smal

First of all, thank you for migrating CarouselView to MAUI!

We faced with a crash, when using regular navigation in the .NET MAUI App project, e.g:
MainPage = new NavigationPage(new MainPage()); (imagine MainPage contains CarouselView)

Java.Lang.NullPointerException crash happens in CarouselViewRenderer.SetNativeView on Android.

It happens because context is StackNavigationManager_StackContext which derives from AndroidX.AppCompat.View.ContextThemeWrapper but CarouselViewRenderer.FindActivity method expects Android.Views.ContextThemeWrapper. So, FindActivity returns null and NullPointerException occurs in CarouselViewRenderer.SetNativeView method.
Screenshot 2023-12-12 at 14 23 53

You can reproduce this issue on the sample project attached.
NullPointerCrashDemo.zip

A FIX is to use Android.Content.ContextWrapper class which contains BaseContext we are looking for and is base class for both AndroidX.AppCompat.View.ContextThemeWrapper and Android.Views.ContextThemeWrapper.

I will create a fork with fix to speed up fix of this issue.

Will appreciate if you can handle it as soon as possible.

Regards,
Vitalii

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions