Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a NullReferenceException #22

Open
dush135 opened this issue Oct 17, 2019 · 5 comments
Open

Getting a NullReferenceException #22

dush135 opened this issue Oct 17, 2019 · 5 comments

Comments

@dush135
Copy link

dush135 commented Oct 17, 2019

I am using this plugin in my xamarin forms app. But when I want to change the orientation to Landscape app getting crash and giving me a NullReferenceException in Android.

Android version 9(Pie)
Xamarin.Forms version is 4.2.0.848062

@yagha766
Copy link

yagha766 commented Feb 9, 2020

I am getting the same error here NullReferenceException and I am using it in Xamarin Forms
Is there a solution ???

CurrentOrientation is null

@thisisthekap
Copy link

The issues also arises regulary for several of our customers (According to AppCenter Crash Reporting). Therefore, unfortunately we are not able to provide a reproduction. Does anyone have some clue what could possibly be the cause of this issue?

@wcoder
Copy link
Owner

wcoder commented May 18, 2020

@thisisthekap Could you please provide some information:

  • Which version of Xamarin.Forms do you use?
  • Which platform?

@thisisthekap
Copy link

thisisthekap commented May 18, 2020

@wcoder Currently we are using Xamarin.Forms 4.6.0.726

Here a list of Android devices and OS versions where we detected the issue:

Device OS Version
F11 Pro 9
Galaxy A40 9
Galaxy A50 9
Galaxy A7 (2018) 9
Galaxy J2 Prime 6.0.1
Galaxy Note5 7.0
Galaxy Note8 9
Galaxy S10 9
J8 5.1
Le Max2 6.0.1
M6 7.0
Mate 20 9
MI 8 Lite 9
Mi A2 9
P20 lite 9
VIBE X3 Lite 6.0

Edit:

The issue was never detected on iOS devices.

@wcoder wcoder added the Android label May 22, 2020
@ccsousa01
Copy link

ccsousa01 commented Jul 9, 2020

I experienced the same issue using Xamarin Forms v4.7.0.968 but discovered this line CrossCurrentActivity.Current.Activity = this; within the protected override void OnCreate(Bundle savedInstanceState) MainActivity.cs file for the Android project. This requires the namespace using Plugin.CurrentActivity; . This solved the issue for me and the null reference error no longer appeared when I attempted to force a specific page, in my shared project, to only utilize portrait mode protected override void OnAppearing() { base.OnAppearing(); try { if (Device.Idiom == TargetIdiom.Phone && CrossDeviceOrientation.IsSupported) CrossDeviceOrientation.Current.LockOrientation(Plugin.DeviceOrientation.Abstractions.DeviceOrientations.Portrait); } catch (Exception) { //TODO: log exception } }

P.s. ensure you have the nuget package installed for each project. Xamarin.Forms sample

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

No branches or pull requests

5 participants