新风 2013-12-12 10:25
浏览 1099

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

错误的问题!

未将对象引用设置到对象的实例。

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:

行 40:
行 41: Application.Lock();
行 42: ((Panel)Application["char"]).Controls.AddAt(0,lbr);
行 43: ((Panel)Application["char"]).Controls.AddAt(0,_words);
行 44: ((Panel)Application["char"]).Controls.AddAt(0,_dt);

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 简易聊天室 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"] == null) {
Response.Redirect("聊天室登录.aspx");
}

    if (Application["chat"] == null) {
        Application["chat"] = new Panel();
    }

    Panel1.Controls.Add((Panel)Application["chat"]);
}
protected void Button2_Click(object sender, EventArgs e)
{
    Session.Remove("uid");
    Response.Redirect("聊天室登录.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
    Label _uid = new Label();
    _uid.Text = Session["uid"].ToString();

    Label _dt = new Label();
    _dt.Text = DateTime.Now.ToLongTimeString();

    Label _words = new Label();
    _words.Text = TextBox1.Text;

    Literal lbr=new Literal();
    lbr.Text="<br/>";

    Application.Lock();
       ((Panel)Application["char"]).Controls.AddAt(0,lbr);
       ((Panel)Application["char"]).Controls.AddAt(0,_words);
       ((Panel)Application["char"]).Controls.AddAt(0,_dt);
       ((Panel)Application["char"]).Controls.AddAt(0,_uid);
    Application.UnLock();
}

}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作