C# WinForm 未将对象引用到实例 图片地址:http://hi.csdn.net/space-300592-do-album-picid-987380-goto-up.html这个问题真不好意思提出来啊,总是说未将对象引用到实例,但是FrmMain这个窗体是存在的,求解中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码哪个地方引用了null值,得有代码才知道 *********************************************************************************************************登录页面的提交按钮事件 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()); } } }} Application.Run(new FrmMain());这一行代码报错,但是我通过可视化界面已经看到这个窗体的信息了,比如窗体上面的Text等等。也就是说这个窗体确实已经实例化了一个了。 你说这个报错跟麽说一样:Application.Run(new FrmMain());报错的也不是出在new FrmMain上而是出在Application.Run内部而你的所有代码都是被这个函数直接或间接调用的对应该去找堆栈最顶层的那个函数 FrmMain_Load里抛了异常,调试进去看 FrmMain_Load都还没有执行呢,程序还没走到这一步。 Icedmilk:Application.Run内部出错?有什么办法可以看得到Application.Run内部的执行过程? 感谢楼上的各位,我找到问题了:我在函数里面增加了一句Application.Exit();但是我不知道具体是什么原因,貌似是类似资源释放的问题,各位觉得呢? public FrmMain() { InitializeComponent(); Application.Exit(); } 解析JSON 有个问题啊 如何在C#中绘制长方体 C# 泛型集合问题,高手过来看看。 穷人无分--问--如何将pictureBox1里面的图片变成黑白 visualC# 2008Express没有水晶报表功能怎么办? 请教:WinForm中调用WinRar,如何等待压缩文件生成以后,再执行压缩文件的拷贝。谢谢! c#,如何往数据库中插入 "网络\" 这样的记录 ? 一个奇怪的问题?好几天了没有解决?望高手指点! 查询返回的记录行数为什么总是负值 Decoder.convert方法的疑问 新手,一个GPS.DLL 的类我怎么调用?
*********************************************************************************************************登录页面的提交按钮事件
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());
}
}
}
}
Application.Run(new FrmMain());
这一行代码报错,但是我通过可视化界面已经看到这个窗体的信息了,比如窗体上面的Text等等。
也就是说这个窗体确实已经实例化了一个了。
Application.Run(new FrmMain());报错的也不是出在new FrmMain上
而是出在Application.Run内部而你的所有代码都是被这个函数直接或间接调用的对应该去找堆栈最顶层的那个函数
FrmMain_Load都还没有执行呢,程序还没走到这一步。
Icedmilk:Application.Run内部出错?
有什么办法可以看得到Application.Run内部的执行过程?
{
InitializeComponent();
Application.Exit();
}