C# 获取了未设置为对象实例的异常对象引用

C# 获取了未设置为对象实例的异常对象引用,c#,.net,C#,.net,我开发了一个windows应用程序(C#.net)。我得到了一个例外,对象引用没有设置为对象的实例 堆栈跟踪是 在OnamVideoCable.Bill\u Generate.btnBill\u单击(对象发送方,事件参数 e) 在 C:\FinalOnam\CableOperatorSoftware\OnamVideoCable\OnamVideoCable\Bill Generate.cs:第179行 在System.Windows.Forms.Control.OnClick(EventArg

我开发了一个windows应用程序(C#.net)。我得到了一个例外,对象引用没有设置为对象的实例

堆栈跟踪是

在OnamVideoCable.Bill\u Generate.btnBill\u单击(对象发送方,事件参数 e) 在 C:\FinalOnam\CableOperatorSoftware\OnamVideoCable\OnamVideoCable\Bill Generate.cs:第179行

在System.Windows.Forms.Control.OnClick(EventArgs e)中

在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs-mevent)上

在System.Windows.Forms.Control.WmMouseUp(Message&m,MouseButtons)中 按钮,Int32次单击)

位于System.Windows.Forms.Control.WndProc(Message&m)

位于System.Windows.Forms.ButtonBase.WndProc(Message&m)

在System.Windows.Forms.Button.WndProc(Message&m)中

在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)

在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr)中 hWnd、Int32 msg、IntPtr wparam、IntPtr lparam)

在System.Windows.Forms.UnsafentiveMethods.DispatchMessageW(MSG& 味精)

在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafentiveMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID、Int32原因、Int32数据)

在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因(应用程序上下文上下文)

在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因(应用程序上下文上下文)

在中的OnamVideoCable.Program.Main()处 C:\FinalOnam\CableOperatorSoftware\OnamVideoCable\OnamVideoCable\Program.cs:line 十九,

位于System.AppDomain.\u nexecutestAssembly(程序集,字符串[]) args)

在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

在System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback回调、对象状态)

位于System.Threading.ThreadHelper.ThreadStart()处

代码:

私有无效BTN单击(对象发送者,事件参数e) { int-CustNo=0; int发薪月; objB.OB=Convert.ToDouble(txtOB.Text)


查看Generate.cs:line 179,检查您在这一行中使用的变量,其中一个为null

查看Generate.cs:line 179,检查您在这一行中使用的变量,其中一个为null

,因此请仔细查看(或接近-数字可能会有几行)

在OnamVideoCable.Bill\u Generate.btnBill\u单击C:\FinalOnam\CableOperatorSoftware\OnamVideoCable\OnamVideoCable\Bill Generate.cs:第179行中的(对象发送方,事件参数e)

其中的某些内容为空。请添加断点并使用调试器。检查空值,或者修复使其意外为空的任何内容。我无法告诉您什么-我看不到您的代码!

因此请仔细查看中的第179行(或在附近-数字可能为几)

在OnamVideoCable.Bill\u Generate.btnBill\u单击C:\FinalOnam\CableOperatorSoftware\OnamVideoCable\OnamVideoCable\Bill Generate.cs:第179行中的(对象发送方,事件参数e)


其中的某些内容为空。请添加断点并使用调试器。要么检查空值,要么修复使其意外为空的任何内容。我不能告诉您什么-我看不到您的代码!

当您访问它时,某些内容为空值。请向我们显示btnBill\u Click的代码。哪个对象引发异常?尝试初始化该特定对象object.something在您访问它时为null请向我们显示btnBill\u Click的代码。哪个对象引发异常?尝试初始化该特定对象。调试项目时,我没有收到异常。正在关闭私有void btnBill\u Click()的花括号调试项目时,我没有发现异常。关闭private void btnBill_Click()@sonal的花括号,哪一行是第179行?关闭private void btnBill_Click()@sonal的花括号,然后(另请参见您对调试器的评论)您需要稍微分解此方法(将其重构为方法)并添加日志记录/某种“爆炸时我在做什么”信息。我们无法为您调试它。玩得开心。您能详细说明一下吗?我有300多个客户,所以完成每个循环需要很多时间。@sonal“详细说明”?当然:其中一行正在做一些得到空值的事情,但没有处理它。只有你能找到。我们不是通灵者。调试它。这并不总是意味着“使用调试器”。这是你工作的基本部分,所以……去做吧。@sonal哪一行是179行?关闭私有void的花括号btnBill_Click()@sonal然后(还可以看到你对调试器的评论)你需要将这个方法分解一下(将它重构为方法)并添加日志记录/某种“我爆炸时在做什么”的信息。我们不能为你调试它。玩得开心。你能详细说明一下吗?我有300多个客户,所以完成每个循环需要很多时间。@sonal“精心设计”?当然:其中一行是在做一些得到空值的事情,而不是处理它。只有你能找到。我们不是通灵的。调试它。这并不总是意味着“使用调试器”。这是你工作的基本部分,所以…去做吧。
        if (ddCustSelect.Text == "All Customers")
        {
            try
            {
                DataTable dtCustNo = objCust.GetCustInfoForBill();
                foreach (DataRow drCustNo in dtCustNo.Rows)
                {
                     CustNo = Convert.ToInt32(drCustNo["CustNo"]);
                     DataTable dtR = new DataTable();
                        dtR=objR.GetLastReceiptInfo(CustNo);
                    if (dtR != null)
                    {
                        if (dtR.Rows.Count > 0)
                        {
                            DataRow drR = dtR.Rows[0];
                            //groupBox1.Visible = true;
                            //lblReceipt.Text = Convert.ToString(drR["RNo"]);
                            //lblPaidAmt.Text = Convert.ToString(drR["Amount"]);
                            // lbloutstand.Text = Convert.ToString(drR["Balance"]);
                            //lblMonthRate.Text = Convert.ToString(drR["MonthlyRate"]);
                            DateTime paydate = Convert.ToDateTime(drR["date"]);
                            //lblPayMonth.Text = Convert.ToString(drR["paydate"]);
                            PayMonth = paydate.Month;
                            objB.LastOut = Convert.ToDouble(drR["Balance"]);
                            total = calculate_bill(PayMonth, ddMonth.SelectedIndex + 1, Convert.ToDouble(drR["Balance"]), Convert.ToDouble(drR["MonthlyRate"]));
                        }
                        else
                        {
                            PayMonth = ddMonth.SelectedIndex + 1;
                            DataTable dtRate = objRate.GetExistCustRate(CustNo);
                            DataRow drRate = dtRate.Rows[0];
                            //total = calculate_bill(PayMonth, ddMonth.SelectedIndex + 1, 0, Convert.ToDouble(drRate["Total"]));
                            //objB.LastOut = 0;
                            total = Convert.ToDouble(drRate["Total"]);
                            objB.LastOut = total;
                        }
                    }
                    else
                    {
                        PayMonth = ddMonth.SelectedIndex + 1;
                        DataTable dtRate = objRate.GetExistCustRate(CustNo);
                        DataRow drRate = dtRate.Rows[0];
                        //total = calculate_bill(PayMonth, ddMonth.SelectedIndex + 1, 0, Convert.ToDouble(drRate["Total"]));
                        //objB.LastOut = 0;
                        total = Convert.ToDouble(drRate["Total"]);
                        objB.LastOut = total;
                        //MessageBox.Show("Table is null");
                    }
                    objB.CustNo = Convert.ToInt32(CustNo);
                    objB.Month = ddMonth.Text;
                    objB.Year = ddYear.Text;
                    objB.Total = total;

                    DataTable dtBill = new DataTable(); 
                       dtBill = objB.checkBill();
                       if (dtBill != null)
                       {
                           if (dtBill.Rows.Count > 0)
                           {
                               // MessageBox.Show("Bill is Already Generated");
                               continue;
                           }
                           else
                           {
                               objB.GenerateBill();

                           }
                       }
                       else
                       {
                           //MessageBox.Show("2nd table is null");
                           objB.GenerateBill();
                       }

                }
                MessageBox.Show("Bill is generated");
            }
            catch (Exception ex)
            {
               // MessageBox.Show(ex.Message + CustNo);
                throw ex;
            }
        }
        if (ddCustSelect.Text == "Single Customer")
        {
            try
            {
                //panelSingle.Visible = true;
                // groupBox1.Visible = true;
                objB.CustNo = Convert.ToInt32(ddCustNo.Text);
                objB.Month = ddMonth.Text;
                objB.Year = ddYear.Text;
                objB.Total = Convert.ToDouble(lblTotalBill.Text);
                if (lbloutstand.Visible)
                {
                    objB.LastOut = Convert.ToDouble(lbloutstand.Text);
                }
                else
                {
                    objB.LastOut = objB.Total;
                }

                DataTable dtBill = objB.checkBill();
                if (dtBill != null)
                {
                    if (dtBill.Rows.Count > 0)
                    {
                        MessageBox.Show("Bill is Already Generated");
                    }
                    else
                    {
                        if (objB.GenerateBill())
                        {
                            MessageBox.Show("Bill is generated..");
                        }
                        else
                        {
                            MessageBox.Show("Error while generating bill");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("2nd table null");
                }
            }
            catch(Exception)
            {
            }


        }
    }----this is line no 179