未处理的异常错误(Xaramin Android)

时间:2018-02-09 07:45:18

标签: c# android visual-studio

我一直收到此错误,我不确定如何修复它。谁能帮我? (入门编程/ Xaramin) PS:mBtnSignUp.Click + = ....代码可以正常工作+显示对话框,但SignIn没有,但它是相同的代码+代码ID也是正确的。

错误: System.NullReferenceException:未将对象引用设置为对象的实例。

给我错误的部分代码:

mBtnSignIn.Click += (object sender, EventArgs args) =>
        {
            //Dialog opvragen
            FragmentTransaction transaction = FragmentManager.BeginTransaction();
            dialog_SignIn signInDialog = new dialog_SignIn();
            signInDialog.Show(transaction, "Dialog fragment");

            signInDialog.mOnSignInComplete += SignInDialog_mOnSignInComplete;
        };

完整代码:

protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            mBtnSignUp = FindViewById<Button>(Resource.Id.btnRegistreren);
            mBtnSignIn = FindViewById<Button>(Resource.Id.btnInloggen);
            mProgressBar = FindViewById<ProgressBar>(Resource.Id.progressBar1);

            mBtnSignIn.Click += (object sender, EventArgs args) =>
            {
                //Dialog opvragen
                FragmentTransaction transaction = FragmentManager.BeginTransaction();
                dialog_SignIn signInDialog = new dialog_SignIn();
                signInDialog.Show(transaction, "Dialog fragment");

                signInDialog.mOnSignInComplete += SignInDialog_mOnSignInComplete;
            };

            mBtnSignUp.Click += (object sender, EventArgs args) =>
            {
                //Dialog opvragen
                FragmentTransaction transaction = FragmentManager.BeginTransaction();
                dialog_SignUp signUpDialog = new dialog_SignUp();
                signUpDialog.Show(transaction, "Dialog fragment");

                signUpDialog.mOnSignUpComplete += SignUpDialog_mOnSignUpComplete;
            };
        }

        void SignInDialog_mOnSignInComplete(object sender, OnSignInEventArgs e) //Inloggen
        {
            mProgressBar.Visibility = ViewStates.Invisible;
            Thread thread = new Thread(ActLikeARequest);
            thread.Start();
        }

        void SignUpDialog_mOnSignUpComplete(object sender, OnSignUpEventArgs e) //Registreren
        {

            mProgressBar.Visibility = ViewStates.Invisible;
            Thread thread = new Thread(ActLikeARequest);
            thread.Start();
        }

        private void ActLikeARequest()
        {
            Thread.Sleep(3000);

            RunOnUiThread(() => { mProgressBar.Visibility = ViewStates.Invisible; });
        }

我希望我的问题是可以理解的。

提前致谢!

1 个答案:

答案 0 :(得分:0)

通过按“继续”并查看输出窗口,可以在发生未处理的错误时取消代码的错误和行。

这里通常会有很多内容,但是如果仔细观察,如果您正在运行模拟器或使用设备的远程调试,它将为您提供线索和行号

另一种方法是将有问题的代码包装在try catch中并断开异常并查看堆栈跟踪

try
{
    // code
}
catch(Exception ex)
{  // << break point here

}

此外,在制作中,您可以使用HockeyApp监控崩溃

其他资源

Using Breakpoints

How to integrate HockeyApp with Xamarin