首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • System.NullReferenceException: Object reference not set to an instance of an object.异常
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 00:02:52 楼主
    我的程序在本机运行正常,但发布到服务器时,提交信息的时候有时会提示下面的错误: 
    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
      UserControl_friend.bntSubmit_Click(Object sender, ImageClickEventArgs e) +2036
      System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +105
      System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
      System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
      System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
      System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
      System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

    调试也没有发现任何的异常,,而且在本地用iis也都正常,,,但是在服务器上面提交信息的时候,第一次可以正常,再提交(当然信息也是另外输入的)的时候就出现异常了

    各位大虾帮帮忙啊。。。小女子先谢谢了。。。
    50  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 00:10:161楼 得分:0
    怎么都没有人来的:(
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • lalac
    • 等级:
    发表于:2007-10-09 07:53:142楼 得分:0
    检查你的UserControl_friend.bntSubmit_Click(Object sender, ImageClickEventArgs e)中的代码。
    应该在这个文件的第2036行,看看那个变量是null的。

    或者把这个函数贴出来吧。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 09:16:453楼 得分:0
    这个文件没有那么多行啊。。。最后一个字符也是第197行,没有第2036行

    protected void bntSubmit_Click(object sender, ImageClickEventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
            if (Request.Cookies["CheckCode"] == null)
            {
                return;
            }
            if (String.Compare(Request.Cookies["CheckCode"].Value, this.txtDatabase.Value, true) != 0)
            {
                lblMsg.Visible = true;
                lblMsg.Text = "验证码不正确!";
                return;
            }

            if (txtMap.Value.Trim() != "")
            {
                if (GetUploadImgs(txtMap) == null)
                {
                    return;
                }
            }

            if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
            {
                string title = txtTitle.Value.Trim();
                string self = txtDesc.Value.Trim();
                string email = txtEmail.Value.Trim();
                string name = txtName.Value.Trim();
                string tel = txtTel.Value.Trim();
                string other = txtOther.Value.Trim();
                string picpath = GetUploadImgsUrl();
                if (picpath != "0")
                {
                    string[] cols = { "title", "self", "email", "name", "tel", "other", "picpath", "createtime" };
                    string[] values = { title, self, email, name, tel, other, picpath, DateTime.Now.ToString() };
                    service.UpdateFriend(cols, values, Request.QueryString["ID"]);
                    lblMsg.Visible = true;
                    lblMsg.Text = "保存成功!";
                }
                else
                {
                    string[] cols = { "title", "self", "email", "name", "tel", "other", "createtime" };
                    string[] values = { title, self, email, name, tel, other, DateTime.Now.ToString() };
                    service.UpdateFriend(cols, values, Request.QueryString["ID"]);
                    lblMsg.Visible = true;
                    lblMsg.Text = "保存成功!";
                }
            }
            else
            {
                Entities.friend friend = EntityFactory <Entities.friend>.CreateObject();
                friend.title = txtTitle.Value.Trim();
                friend.picpath = GetUploadImgsUrl();
                DataTable citydt = service.FindArea(" and id=" + Request.QueryString["areaid"]).Tables[0];
                friend.city = int.Parse(GetRoots(citydt, 1));
                DataTable areadt = service.FindArea(" and parentid=" + GetRoots(citydt, 1)).Tables[0];
                if (areadt.Rows.Count > 0)
                {
                    friend.area = int.Parse(areadt.Rows[0]["id"].ToString());

                    DataTable streetdt = service.FindArea(" and parentid=" + areadt.Rows[0]["id"].ToString()).Tables[0];
                    if (streetdt.Rows.Count > 0)
                    {
                        friend.street = int.Parse(streetdt.Rows[0]["id"].ToString());
                    }
                }
                friend.categoryid = int.Parse(Request.QueryString["categoryid"]);
                friend.createid = int.Parse(Session["Userid"].ToString() == "" ? "0" : Session["Userid"].ToString());
                friend.createtime = DateTime.Now;
                friend.email = txtEmail.Value.Trim();
                friend.name = txtName.Value.Trim();
                friend.other = txtOther.Value.Trim();
                friend.self = txtDesc.Value.Trim();
                friend.tel = txtTel.Value.Trim();
                service.InsertFriend(friend);

                lblMsg.Visible = true;
                lblMsg.Text = "保存成功!";
            }
        }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 11:05:004楼 得分:0
    有没有人啊
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 11:26:505楼 得分:0
    反正你的这段代码又不长,你就一个一个变量看看,哪个变量是null不就知道哪错了么
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 13:35:046楼 得分:0
    先单步调看哪句报错
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 13:44:537楼 得分:0
    单步调试,看那个变量为null
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 13:45:548楼 得分:0
    调试是没有任何异常的。。。。

    发布之后在在本地的iis运行也没有任何问题。。。

    但是放到服务器上就出现的这样的异常。。。

    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2007-10-09 13:50:089楼 得分:0
    compilation debug="true"
    或上服务器  运行,就能报出错误在哪里
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved