我再一次出现这种错误!上一次出现这种错误,没有找到好的解决方法,只有绕开它,用其他方法来作,但是现在居然又出现这个问题,绕开是没办法,那位高手帮手解决!让我不再出现这种问题!感谢!分不够可以加!只要能帮我解决!谢谢!

解决方案 »

  1.   

    这个问题是你写代码的问题..是饶不开的.你哪个对象为null了..你可以多写点if(XX==null)的判断。
      

  2.   

    你的对象是null啊。把可能出现null的对象都check一下
      

  3.   

    protected void BtsubortNew_Click(object sender, EventArgs e)
        {        string users = Session["UserLoginID"].ToString();
            string usid = sqldb.scr("select manager_id from manager where manage_nm='" + users + "'");        string filetype = fUlimage.PostedFile.ContentType.ToString();        string name = fUlimage.PostedFile.FileName;
            FileInfo file = new FileInfo(name);
            string fileName = file.Name; // 文件名称 
            string fileName_s = "s_" + file.Name; // 缩略图文件名称 
         
            string webFilePath = Server.MapPath("file/" + fileName); // 服务器端文件路径 
            string webFilePath_s = Server.MapPath("file/" + fileName_s);  // 服务器端缩略图路径 
            
            if (fUlimage.HasFile)
            {
                if (filetype == "image/bmp" || filetype == "image/gif" || filetype == "image/pjpg")
                {                    if (!File.Exists(webFilePath))
                    {
                        try
                        {
                            fUlimage.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 
                            //AddShuiYinWord(webFilePath, webFilePath_sy);
                            //AddShuiYinPic(webFilePath, webFilePath_syp, webFilePath_sypf);
                            MakeThumbnail(webFilePath, webFilePath_s, 115, 123, "Cut"); // 生成缩略图方法 
                            string Ntitle = tbtitle.Text;
                            string Ncontent = this.FCKnew.Value.ToString();
                            string Nmenu = this.DDlmenu.SelectedValue.ToString();
                            string newid = Convert.ToString(Request.QueryString["id"]);
                            if (newid == null)
                            {
                                if (Ntitle != "" && Ncontent != "" && usid != "" && Nmenu != "" && fileName_s!="")
                                {
                                    string str = "insert into new(new_cn,newC_cn,usr_id,menu_id,new_pic) values('" + Ntitle + "','" + Ncontent + "','" + usid + "','" + Nmenu + "','" + fileName_s + "')";
                                    if (sqldb.insert(str) == true)
                                    {
                                        PopMsgBox("保存成功!");
                                    }
                                    else
                                    {
                                        PopMsgBox("保存失败!");
                                    }
                                }
                                else
                                {
                                    PopMsgBox("不允许为空!");
                                }                        }
                            else
                            {
                                if (Ntitle != "" && Ncontent != "" && usid != "" && newid != "" && fileName_s!="")
                                {
                                    string strtitle = sqldb.scr("select new_cn from new where new_id='" + newid + "'");
                                    tbtitle.Text = strtitle;
                                    string strn = "update new set newC_cn='" + Ncontent + "' where new_id='" + newid + "' and new_cn='" + strtitle + "' and new_pic='" + fileName_s + "'";
                                    if (sqldb.insert(strn) == true)
                                    {
                                        PopMsgBox("更新成功!");
                                    }
                                    else
                                    {
                                        PopMsgBox("更新失败!");
                                    }
                                }
                                else
                                {
                                    PopMsgBox("不允许为空!");
                                }                        }                    }
      

  4.   


    catch (Exception ex)
                        {
                            PopMsgBox("提示:文件上传失败,失败原因:"+ex.Message);
                        }
                    }
                    else
                    {
                        PopMsgBox("提示:文件已经存在,请重命名后上传");
                    }
                }
                else
                {
                    PopMsgBox("提示:文件类型不符");
                }        }
            else
            {
                PopMsgBox("提示:请上传图片");
            }
        }
            
                
        protected void BtcanelNew_Click(object sender, EventArgs e)
        {
            DDlmenu.SelectedValue = "1";
            tbtitle.Text = null;
            FCKnew.Value = null;
        }
      

  5.   


         if (!IsPostBack)
            {
                string newid = Convert.ToString(Request.QueryString["id"]);
                if (newid != null)
                {
                    DDlmenu.SelectedValue = sqldb.scr("select menu_id from new where new_id='" + newid + "'");
                    tbtitle.Text = sqldb.scr("select new_cn from new where new_id='"+newid+"'");
                    FCKnew.Value = sqldb.scr("select newC_cn from new where new_id='" + newid + "'");
                    
                }
                else
                {
                    string dmid = Convert.ToString(DDlmenu.SelectedValue);
                    
                }
            }
            
      

  6.   

    代码太长了。
    懒的看了
    首先比较的时候
    应该是常量在前面 变量在后面第2 可能出现null的地方是
    MakeThumbnail(webFilePath, webFilePath_s, 115, 123, "Cut"); 
    this.FCKnew.Value.ToString();string Nmenu = this.DDlmenu.SelectedValue.ToString();下面的我就不看了。
      

  7.   


    fUlimage.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 
    MakeThumbnail(webFilePath, webFilePath_s, 115, 123, "Cut"); // 生成缩略图方法 出错的应该是这两个地方,插个断点看看,是不是空值
      

  8.   

    代码太长,应该是有一个对象null的问题,多捕捉检查就好,