Object reference not set to an instance of an object

I have a strange behaviour in this code:

UIApplication.SharedApplication.InvokeOnMainThread(
    new NSAction(() => {
    try
    {
    this.NavigationController.PopViewControllerAnimated(true);
    this.loginController = new LoginController();
    this.NavigationController.PushViewController(loginController,true);
    }
    catch (Exception ex) {
        Console.WriteLine (ex.Message);
    }
    })


    );

at this line
this.NavigationController.PushViewController(loginController,true);
The compiler return me the error in the thread title.
loginController is declared globally in the UIViewController class then an istance is created
before to call the method PushviewController
Please help me to understand where do I'm wrong.
Max.

Posts

  • SKallSKall USMember ✭✭✭✭

    Most likely it is a null reference inside your LoginController. Put a breakpoint on the first line of LoginController.ViewDidLoad() function and see if it breaks. If it does, step through to find the null reference.

  • No It doesn't break, but the logincontroller is showed the same.
    My navigation flow is (root) LoginController->myActualview
    so when I do this.NavigationController.PushViewController(loginController,true);
    I'm going back to the first root view because I have in Appdelegate:

    //---- instantiate a new home screen 
                LoginController loginScreen = new LoginController(); 
    
                //---- add the home screen to the navigation controller 
                // (it'll be the top most screen) 
                rootNavigationController.PushViewController(loginScreen, false); 
    
                //---- set the root view controller on the window. the nav 
                // controller will handle the rest 
                this.window.RootViewController = rootNavigationController; 
                this.window.MakeKeyAndVisible ();
    
  • RaghukothaRaghukotha INMember
    edited July 2015

    Hi ,
    this my code i am getting exception while clicking alert view ok button to navigate to view controller

    System.NullReferenceException: Object reference not set to an instance of an object
    at ThreeDID.iOS.ScanController.AlertAccountName_Clicked (System.Object sender, UIKit.UIButtonEventArgs e) [0x0007f] in /Users/macmini/Projects/ThreeDID.bak/ThreeDID.iOS/ScanController.cs:420
    at UIKit.UIAlertView+_UIAlertViewDelegate.Clicked (UIKit.UIAlertView alertview, nint buttonIndex) [0x00014] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/build/ios/native/UIKit/UIAlertView.g.cs:448
    at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/UIKit/UIApplication.cs:63
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/UIKit/UIApplication.cs:46
    at ThreeDID.iOS.Application.Main (System.String[] args) [0x00008] in /Users/macmini/Projects/ThreeDID.bak/ThreeDID.iOS/Main.cs:17

    void AlertAccountName_Clicked(object sender, UIButtonEventArgs e)
    {
        if (e.ButtonIndex == 0)
        {
            string accountName = alertAccountName.GetTextField(0).Text.Trim();
            if (accountName != "")
            {
                var nameExists = App.Resolve<DataLayer>().CheckAccountNameExists(accountName);
                if (nameExists)
                {
                    BTProgressHUD.ShowErrorWithStatus("this account name is already existed");
                }
                else
                {
                        NavigationController.PushViewController(new LinkcodeController(accountName), true);
                }
            }
            else
            {
                BTProgressHUD.ShowErrorWithStatus("Please enter account name ");
                Alertview();
            }
        }
        else
        {
            Console.WriteLine("Cancel button is clicked");
        }
    }
    

    please help me with this

  • Did you get it solved?!

Sign In or Register to comment.