Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

Setting MainPage throws exception on Android

$
0
0

Hello all,

I have a strange Android-only bug that throws when I go to set the App's MainPage. Here is the code that throws:

private void onTryLoginComplete(object sender, EventArgs args)
        {
            try
            {
                //await Navigation.PopAsync();
                if (AppUser.IsSignedIn)
                {
                    var castArgs = (args as LoginClosedEventArgs);
                    if (castArgs == null)
                    {
                        //TODO handle null case
                    }
                    else if (castArgs.LoginResult == SignInResult.Success)
                    {
                        var mainMasterDetail = PageFactory.BuildMainMasterDetail();
                        MainPage = mainMasterDetail;
                    }
                    else if (castArgs.LoginResult == SignInResult.UasOnlyExists)
                    {
                        //TODO info gather page here
                        var addInfoPage = PageFactory.BuildAddInfoPage();
                        addInfoPage.PageClosed += onAddInfoPageClosed;
                        MainPage = addInfoPage;
                    }
                }
                else
                {
                    openLogin(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }

Here is some code that sets the MainPage that does not throw:

`
protected override void OnStart()
{
// Handle when your app starts
try
{
if (AppUser.IsSignedIn)
{
AppUser.UpdateSelf().ContinueWith(async (task) =>
{
if (task.Exception != null)
{
Debug.WriteLine(task.Exception);
}

                        Debug.Assert(task.Exception == null, "UpdateSelf() failed.");
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainMasterDetail = PageFactory.BuildMainMasterDetail();
                                MainPage = mainMasterDetail;
                            });
                        await TetherAgent.SetCurrentTether();
                    });
            }
            else
            {
                openLogin();
            }
        }
        catch (SignedInNotPairedException e)
        {
            onTryLoginComplete(this, new LoginClosedEventArgs(SignInResult.UasOnlyExists));
        }
    }

`

Here is the exception:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
[MonoDroid] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue*) [0x00084] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
[MonoDroid] at Android.Views.ViewGroup.RemoveView (Android.Views.View) [0x00070] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.ViewGroup.cs:4707
[MonoDroid] at Xamarin.Forms.Platform.Android.NavigationRenderer/<>c__DisplayClass13_0.<SwitchContentAsync>b__0 (Android.Animation.Animator) <IL 0x00048, 0x0019b>
[MonoDroid] at Xamarin.Forms.Platform.Android.NavigationRenderer/<>c__DisplayClass13_1.<SwitchContentAsync>b__1 (Android.Animation.Animator) <IL 0x0000d, 0x0007b>
[MonoDroid] at Xamarin.Forms.Platform.Android.GenericAnimatorListener.OnAnimationEnd (Android.Animation.Animator) <IL 0x0000f, 0x000ab>
[MonoDroid] at Android.Animation.AnimatorListenerAdapter.n_OnAnimationEnd_Landroid_animation_Animator_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Animation.AnimatorListenerAdapter.cs:105
[MonoDroid] at (wrapper dynamic-method) object.7bf59970-2f43-497c-bd34-4bcb84b0a918 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] java.lang.NullPointerException
[MonoDroid]     at android.view.ViewGroup.removeFromArray(ViewGroup.java:3661)
[MonoDroid]     at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3854)
[MonoDroid]     at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3818)
[MonoDroid]     at android.view.ViewGroup.removeView(ViewGroup.java:3750)
[MonoDroid]     at md5282f1122c1313907b9bf274dd2c2f344.GenericAnimatorListener.n_onAnimationEnd(Native Method)
[MonoDroid]     at md5282f1122c1313907b9bf274dd2c2f344.GenericAnimatorListener.onAnimationEnd(GenericAnimatorListener.java:46)
[MonoDroid]     at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1030)
[MonoDroid]     at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1056)
[MonoDroid]     at android.animation.ValueAnimator.access$400(ValueAnimator.java:50)
[MonoDroid]     at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:644)
[MonoDroid]     at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:660)
[MonoDroid]     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
[MonoDroid]     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
[MonoDroid]     at android.view.Choreographer.doFrame(Choreographer.java:543)
[MonoDroid]     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
[MonoDroid]     at android.os.Handler.handleCallback(Handler.java:733)
[MonoDroid]     at android.os.Handler.dispatchMessage(Handler.java:95)
[MonoDroid]     at android.os.Looper.loop(Looper.java:136)
[MonoDroid]     at android.app.ActivityThread.main(ActivityThread.java:5001)
[MonoDroid]     at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid]     at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[MonoDroid]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[MonoDroid]     at dalvik.system.NativeStart.main(Native Method)

Any ideas on why this is happening? Thanks in advance for your help.


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>