图片地址:http://hi.csdn.net/space-300592-do-album-picid-987380-goto-up.html这个问题真不好意思提出来啊,总是说未将对象引用到实例,但是FrmMain这个窗体是存在的,求解中

解决方案 »

  1.   

    代码哪个地方引用了null值,得有代码才知道
      

  2.   


           
    *********************************************************************************************************登录页面的提交按钮事件
     private void btnSubmit_Click(object sender, EventArgs e)
            {
                if (txtUserID.Text.Length == 0)
                {
                    MessageBox.Show("请输入用户ID!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (txtPassword.Text.Length == 0)
                {
                    MessageBox.Show("请输入密码!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    m_DemoSingleton.ServerID = "";                dt = new BLL.SYS_User().GetDataTable_User(txtUserID.Text.Trim());                if (dt.Rows.Count > 0)
                    {
                        if (dt.Rows[0]["Status"].ToString() == "0")
                        {
                            if (dt.Rows[0]["Password"].ToString() == txtPassword.Text.Trim())
                            {
                                                             if (dt.Rows[0]["Description"].ToString().ToUpper() == "R")
                                {
                                    m_DemoSingleton.IsReadOnly = "Y";
                                }
                                else
                                {
                                    m_DemoSingleton.IsReadOnly = "N";
                                }                         
                                DialogResult = DialogResult.OK;                            this.Close();
                                this.Dispose();
                            }
                            else
                            {
                                MessageBox.Show("密码错误!!!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtPassword.SelectAll();
                            }
                        }
                        else
                        {
                            MessageBox.Show("该用户已被停用!!!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            txtUserID.SelectAll();
                        }
                    }
                    else
                    {
                        MessageBox.Show("该用户不存在!!!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtUserID.SelectAll();
                    }
                }
            }
    *********************************************************************************************************登录页面的提交按钮事件*********************************************************************************************************主窗体的加载事件using System;
    using System.Collections.Generic;
    using System.Windows.Forms;namespace StandardManHour
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                FrmLogin flogin = new FrmLogin();
                if (flogin.ShowDialog() == DialogResult.OK)
                {                FrmMain f = new FrmMain();
                    Application.Run(f);
                   
                   // Application.Run(new FrmMain());
                }            
            }
        }
    }
      

  3.   


    Application.Run(new FrmMain());
    这一行代码报错,但是我通过可视化界面已经看到这个窗体的信息了,比如窗体上面的Text等等。
    也就是说这个窗体确实已经实例化了一个了。
      

  4.   

    你说这个报错跟麽说一样:
    Application.Run(new FrmMain());报错的也不是出在new FrmMain上
    而是出在Application.Run内部而你的所有代码都是被这个函数直接或间接调用的对应该去找堆栈最顶层的那个函数
      

  5.   

    FrmMain_Load里抛了异常,调试进去看
      

  6.   


      FrmMain_Load都还没有执行呢,程序还没走到这一步。
      

  7.   


    Icedmilk:Application.Run内部出错?
    有什么办法可以看得到Application.Run内部的执行过程?
      

  8.   

    感谢楼上的各位,我找到问题了:我在函数里面增加了一句Application.Exit();但是我不知道具体是什么原因,貌似是类似资源释放的问题,各位觉得呢?  public FrmMain()
            {
                InitializeComponent();
                Application.Exit();
            }