c#未将对象引用设置到对象的实例怎么发现哪里有问题

图片说明小白一只,不知道还需要什么信息才能让大神参考解决问题

c#

5个回答

以调试方式运行程序,你这个框应该是在代码的try catch里,停下来看哪行出错,检查对应行的变量,有null

ryxczcy
ryxczcy 谢谢大佬
2 年多之前 回复

断点调试,一步一步走。

因为你调用了一个没有赋值的变量

ryxczcy
ryxczcy 谢谢大佬
2 年多之前 回复

设置断点进行调试,才能发现问题

ryxczcy
ryxczcy 谢谢大佬
2 年多之前 回复

在你的“发送文件”按钮事件下断点,哪报错了就知道了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
c# 未将对象引用设置到对象的实例的问题
我自己写了一个控件,在窗体中加载了这个控件,但是在运行时有上述错误。rnprivate void add_time_Click(object sender, EventArgs e)rn rn DateTime dt1 = DateTime.Now;rn if((comboBox1.SelectedIndex>=0) && (comboBox2.SelectedIndex>=0))rn rn string dt2 = dt1.Year + "-" + dt1.Month + "-" + dt1.Day+" "+comboBox1.SelectedIndex+":"+comboBox2.SelectedIndex+":00";rn DateTime dt3 = DateTime.Parse(dt2);rn if (dt3 < dt1)rn rn MessageBox.Show("你输入的时间小于当前时间,非法!");rn rn if (textBox1.Text == "")rn rn MessageBox.Show("您必须设置一个值");rn rn string a = textBox1.Text;rn userControl11.AddTime(dt3, a);rn userControl11.OnTime += my;rn rn elsern if ((comboBox1.SelectedIndex <0) && (comboBox2.SelectedIndex < 0))rn rn MessageBox.Show("输入时间格式不正确"); rn rn rn rnrn这是我的程序中的一段其中Control11.AddTime(dt3, a)是我自定义控件的一个方法,就是在这里出现的错误
未将对象引用设置到对象的实例
起因:文件中的类都不能进行设计,因此未能为该文件显示设计器。设计器检查出文件中有以下类: FormMain --- 未能加载基类“WinForm.Win.FormsBase.FormMainBase”。请确保已引用该程序集并已生成所有项目我用了一个小时找百度。这个的解决方法,就是将你删除过的一个窗体,再添加上就好了。。。。有点生气的。。然后出现了:未将对象引用设置到对象的实例的问题这个问题的解决方...
未将对象引用设置到对象的实例。
我在一个页面定义一个DataTable表 里面已经有数据,把他传到用户控件的后天代码?我是这样写的,为什么老是报出未将对象引用设置到对象的实例。难道穿过来的表是空的吗?[img=https://img-bbs.csdn.net/upload/201404/23/1398214107_854588.jpg][/img][img=https://img-bbs.csdn.net/upload/201404/23/1398214118_325346.jpg][/img][img=https://img-bbs.csdn.net/upload/201404/23/1398214129_620204.jpg][/img]
未将对象引用设置到对象的实例???
private void 音乐试听ToolStripMenuItem_Click(object sender, EventArgs e)rn rn Frm_YinYue x = new Frm_YinYue();rn x.ShowDialog();//就是这里出现问题的rn rn rn 下面的这是Frm_YinYuernrn public partial class Frm_YinYue : Formrn rn //申明一个字符串数组来储存歌曲的地址rn private string[] urlname = new string[2000];rn WMPLib.IWMPMediaCollection mediacollection;rn WMPLib.IWMPMedia media;rnrn //添加单个地址上的mp3文件rnrn private void Addfile(string path)rn rn string songname = path.Substring(path.LastIndexOf('\\') + 1);rn songname = songname.Substring(0, songname.Length - 4);rn mediacollection = axWindowsMediaPlayer1.mediaCollection;rn media = mediacollection.add(path);rn axWindowsMediaPlayer1.currentPlaylist.appendItem(media);rn mediacollection.remove(media, false);rn listBox1.Items.Add(songname);rn urlname[listBox1.Items.Count - 1] = path;rn rnrn public Frm_YinYue()rn rn InitializeComponent();rn rnrn private void 打开文件ToolStripMenuItem_Click(object sender, EventArgs e)rn rn tryrn rn DialogResult result = openFileDialog1.ShowDialog();rn if (result == DialogResult.OK)rn rnrn //songname为歌曲名rn string songname = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);rn songname = songname.Substring(0, songname.Length - 1);rn //刷新当前播放的列表rn axWindowsMediaPlayer1.currentPlaylist.clear();rn //同步刷新listBoxrn listBox1.Items.Clear();rn axWindowsMediaPlayer1.URL = openFileDialog1.FileName;rn this.Text = songname + "--Windows Media Player";rn listBox1.Items.Add(songname);rn urlname[listBox1.Items.Count - 1] = openFileDialog1.FileName;rn //播放当前打开的曲目rn axWindowsMediaPlayer1.Ctlcontrols.play();rnrn rnrn rn catch (Exception error)rn rn MessageBox.Show(error.Message.ToString());rn rn rnrn private void 删除文件ToolStripMenuItem_Click(object sender, EventArgs e)rn rn //listBox1.Items.Clear();//这里的是清除listbox中的所有内容rn listBox1.Items.Remove(listBox1.SelectedItem.ToString ());//此处是删除listbox中选中的项rn // this.axWindowsMediaPlayer1.Ctlcontrols.stop();//停止播放rn rn rnrn private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)rn rn listBox1.Items.Clear();rn rnrn private void 添加单个文件ToolStripMenuItem_Click(object sender, EventArgs e)rn rn tryrn rn DialogResult result = openFileDialog1.ShowDialog();rn if (result == DialogResult.OK)rn rn this.Addfile(openFileDialog1.FileName);rn urlname[listBox1.Items.Count - 1] = openFileDialog1.FileName;rn //播放当前打开的曲目rn axWindowsMediaPlayer1.Ctlcontrols.play();rnrn rn rn catch (Exception error)rn rn MessageBox.Show(error.Message.ToString());rn rn rn private void 播放rlToolStripMenuItem_Click(object sender, EventArgs e)rn rn if (listBox1.Items.Count > 0)rn rn if (this.listBox1.SelectedItems.Count > 0)rn rn if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused)rn rn axWindowsMediaPlayer1.Ctlcontrols.play();rn rn elsern axWindowsMediaPlayer1.Ctlcontrols.pause();rnrn rn rn elsern rn MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);rn rn rnrn private void 上一曲ToolStripMenuItem_Click(object sender, EventArgs e)rn rn tryrn rn if (listBox1.SelectedIndex >= 0)rn listBox1.SelectedIndex = listBox1.SelectedIndex - 1;rn if (listBox1.SelectedIndex < 0)rn rn listBox1.SelectedIndex = listBox1.Items.Count - 1;rn rnrn //这里的代码是:当选择了上一曲后,就立即播放上一曲rnrn WMPLib.IWMPMedia nowmedia = axWindowsMediaPlayer1.currentPlaylist.get_Item(listBox1.SelectedIndex);rn axWindowsMediaPlayer1.Ctlcontrols.playItem(nowmedia);rnrn rn catch (Exception) ;rn rnrn private void 下一曲ToolStripMenuItem_Click(object sender, EventArgs e)rn rn axWindowsMediaPlayer1.Ctlcontrols.next();//这个是系统自带的下一曲方法rnrn tryrn rn if (listBox1.SelectedIndex >= 0)rn listBox1.SelectedIndex = listBox1.SelectedIndex +1;rn if (listBox1.SelectedIndex < 0)rn rn listBox1.SelectedIndex = listBox1.Items.Count +1;rn rnrn //这里的代码是:当选择了上一曲后,就立即播放上一曲rn WMPLib.IWMPMedia nowmedia = axWindowsMediaPlayer1.currentPlaylist.get_Item(listBox1.SelectedIndex);rn axWindowsMediaPlayer1.Ctlcontrols.playItem(nowmedia);rnrn rn catch (Exception) ;rn rnrn rnrn rnrn private void listBox1_DoubleClick(object sender, EventArgs e)rn rn if (listBox1.SelectedIndex > -1)rn rn WMPLib.IWMPMedia nowmedia = axWindowsMediaPlayer1.currentPlaylist.get_Item(listBox1.SelectedIndex);rn axWindowsMediaPlayer1.Ctlcontrols.playItem(nowmedia);rnrn rn rnrn rnrn private void 打开文件ToolStripMenuItem2_Click(object sender, EventArgs e)rn rn 打开文件ToolStripMenuItem_Click(sender, e);rn rnrn private void 上一曲ToolStripMenuItem1_Click(object sender, EventArgs e)rn rn 上一曲ToolStripMenuItem_Click(sender, e);rn rnrn private void 下一曲ToolStripMenuItem1_Click(object sender, EventArgs e)rn rn 下一曲ToolStripMenuItem_Click(sender, e);rn rnrn private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)rn rn axWindowsMediaPlayer1.Ctlcontrols.stop();rn rnrn private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)rn rn DialogResult dr = MessageBox.Show("您确定要退出吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);rn if (dr == DialogResult.Yes)rn this.Close();rn elsern return;rn rnrn private void toolStripMenuItem3_Click(object sender, EventArgs e)rn rn 添加单个文件ToolStripMenuItem_Click(sender, e);rn rnrn private void toolStripMenuItem2_Click(object sender, EventArgs e)rn rn listBox1.Items.Remove(listBox1.SelectedItem.ToString());rn rn rn
未将对象引用设置到对象的实例??
未将对象引用设置到对象的实例。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。rnrn源错误: rnrnrn行 24: using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["CarManage"].ConnectionString))rn行 25: rn行 26: using (SqlCommand command = new SqlCommand("insert into UserMessage(UserName,UPassword,UCode,UName,USex,UBir,UMZ,USFZ,UPhone,UBuMen,UAddress,UPerMissions) values('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox4.Text + "','" + this.TextBox9.Text + "'," + this.RadioButtonList1.SelectedValue + ",'" + birthday.Value + "','" + DropDownListNation.Items[this.DropDownListNation.SelectedIndex].Text + "','" + this.TextBox5.Text + "','" + this.TextBox6.Text + "','" + this.bumen.Items[this.DropDownListNation.SelectedIndex].Text + "','" + this.TextBox7.Text + "','" + RadioButtonList2.SelectedItem.Text + "')"))rn行 27: rn行 28: connection.Open();//打开数据库连接rn rnrn源文件: f:\CarManage\Register.aspx.cs 行: 26 rnrn//源文件rnpublic partial class Register : System.Web.UI.Pagernrn protected void Page_Load(object sender, EventArgs e)rn rnrn rn protected void Button1_Click(object sender, EventArgs e)rn rn using (SqlConnection connection = new SqlConnectionrnrn(ConfigurationManager.ConnectionStrings["CarManage"].ConnectionString))rn rn using (SqlCommand command = new SqlCommand("insert into UserMessagernrn(UserName,UPassword,UCode,UName,USex,UBir,UMZ,USFZ,UPhone,UBuMen,UAddress,UPerMissiornrnns) values('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + rnrnthis.TextBox4.Text + "','" + this.TextBox9.Text + "'," + rnrnthis.RadioButtonList1.SelectedValue + ",'" + birthday.Value + "','" + rnrnDropDownListNation.Items[this.DropDownListNation.SelectedIndex].Text + "','" + rnrnthis.TextBox5.Text + "','" + this.TextBox6.Text + "','" + this.bumen.Itemsrnrn[this.DropDownListNation.SelectedIndex].Text + "','" + this.TextBox7.Text + "','" + rnrnRadioButtonList2.SelectedItem.Text + "')"))rn rn connection.Open();rn command.Connection = connection;rn int result = (int)command.ExecuteNonQuery();rn if (result != 0)rn rn JScript.AlertAndRedirect("登录成功!", "Login.aspx"); rnrn rn elsern rn JScript.AlertAndRedirect("登录失败,请重新输入您的用户名和密码!", "#");rn rn rn rn rnrn[color=#FF0000]rn 乞求高手前来赐教[/color]
未将对象引用设置到对象的实例..
我知道这个很简单 ,但是..但是 我百度了好久都不会- -~ rn求解-,-rn private string connectionstring = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;rn protected void Page_Load(object sender, EventArgs e)rn rn if (!IsPostBack)rn rn show();rn rn rn protected void show()rn rn string m_id = Request["m_id"].ToString();rn SqlConnection con = new SqlConnection(connectionstring);rn con.Open();rn string selectmessage = "select * from message where m_id='" + m_id + "'";rn SqlCommand cmd = new SqlCommand(selectmessage, con);rn SqlDataReader dr = cmd.ExecuteReader();rn if (dr.Read())rn rn this.Tbname.Text = dr["m_name"].ToString();rn this.Tbsubject.Text = dr["m_subject"].ToString();rn this.Tbcontent.Text = dr["m_content"].ToString();rn this.TBreplay.Text = dr["m_replay"].ToString();rn rn dr.Close();rn con.Close();rn
未将对象引用设置到对象实例
我是新手 不知道哪出问题了 我看了 有NULL出现 但是不知道怎么改啊 rn 弹出一个对话框 显示"用户代码未处理NullferenceExceotion"rn具体代码如下rnusing System;rnusing System.Data;rnusing System.Configuration;rnusing System.Web;rnusing System.Web.Security;rnusing System.Web.UI;rnusing System.Web.UI.WebControls;rnusing System.Web.UI.WebControls.WebParts;rnusing System.Web.UI.HtmlControls;rnusing System.Web.Configuration;rnusing System.Data.SqlClient;rnrnpublic partial class _Default : System.Web.UI.Page rnrn protected void Page_Load(object sender, EventArgs e)rn rn string connectionString = WebConfigurationManager.ConnectionStrings["Test"].ConnectionString;rn SqlConnection con = new SqlConnection(connectionString);rn string sql = "select * from '操作员信息'";rn SqlCommand cmd = new SqlCommand(sql, con);rn 显示.Text = sql;rn rn protected void Button1_Click(object sender, EventArgs e)rn rnrn rnrn
未将对象引用设置到对象的实例????????????
未将对象引用设置到对象的实例。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。rnrn源错误: rnrnrn行 82:Db AddDb=new Db();rn行 83:string Sql1;rn行 84:Sql1="update Site_Info set SiteName='"+tbxSiteName.Text+"',SiteManager='"+tbxSiteManage.Text+"',"+rn行 85:"SiteUrl='"+tbxSitePwd.Text+"',ManagePwd='"+tbxSitePwd.Text+"' where Id="+Int32.Parse(lblSiteId.Text);rn行 86: if (AddDb.ExeSql(Sql1)==1)rn rnrnrn行 85:显示红色,什么原因啊
未将对象引用设置到对象的实例?
我做了个Repeater的批量删除,rn页面上是这样的rn rn rn rn rn rn rn rn <%#DataBinder.Eval(Container.DataItem,"Id") %>rn <%#DataBinder.Eval(Container.DataItem,"ISBN") %>rn <%#DataBinder.Eval(Container.DataItem,"bookName") %>rn <%#DataBinder.Eval(Container.DataItem,"price") %>rn <%#DataBinder.Eval(Container.DataItem,"number") %>rn <%#DataBinder.Eval(Container.DataItem,"myang") %>rn <%#DataBinder.Eval(Container.DataItem, "bookSpec")%>rn rn rnrn rncs里代码:rnprotected void Button1_Click(object sender, EventArgs e)rn rn //Button1.Attributes["onclick"] = "return confirm('你确实要删除吗?')";rn rn string ID= "";rn foreach (RepeaterItem item in this.Repeater1.Items)rn rn CheckBox ck = (CheckBox)item.FindControl("CheckBox");rn if (ck.Checked)rn rn HtmlInputHidden inputhidden = (HtmlInputHidden)item.FindControl("fieldname ");rn ID += inputhidden.Value.Trim() + ",";rn rn rn if (ID.Length == 0)rn rn this.Page.RegisterStartupScript(" ", " ");rn rn elsern rn ID = ID.Remove(ID.Length - 1, 1);rn Info.DelId = ID;rn Fun fun = new Fun();rn fun.DelshaixuanId();rn Response.Write(" ");rn rn rn rnrnrnrnrn它说我这句话ID += inputhidden.Value.Trim() + ",";rn未将对象引用设置到对象的实例。什么意思啊?
◆未将对象引用设置到对象的实例◆
声明了以下方法用于上传图片.程序开始调试是正常的,可以上传图片,后来我在控件外面加了一个UpdatePanel ,再点Upload上传时,程序执行到下面红颜色一行代码是出现:"未将对象引用设置到对象的实例"错误提示!请教如何解决!!??rn protected void UploadImg_Click(object sender, EventArgs e)rn rn string fullname = File1.FileName.ToString();rn string fn = DateTime.Now.ToString("yyyyMMddHHmmss") + fullname;rn string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1);rn [color=#FF0000]string size = File1.PostedFile.ContentLength.ToString();[/color]rn if (typ2 == "jpg" || typ2 == "gif")rn rn File1.SaveAs(Server.MapPath("img") + "\\" + fn);rn Response.Write(" ");rn this.ImgUrl.Text = "img/" + fn;rn this.shipPhoto.ImageUrl = "img/" + fn;rn rn elsern rn Response.Write(" ");rn rn
未将对象引用设置到对象的实例!
未将对象引用设置到对象的实例 !rnrn是怎么回事!rnrn
未将对象引用设置到对象的实例 ???
未将对象引用设置到对象的实例。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。rnrn源错误: rnrnrn行 21: private void Page_Load(object sender, System.EventArgs e)rn行 22: rn行 23: string id=Request["Tname"].ToString();rn行 24: string pass=Request["Tpass"].ToString();rn行 25: if(id=="a"&&pass=="a")rn rn
未将对象引用设置到对象的实例??
做搜索时,单击搜索出现未将对象引用设置到对象的实例.什么意思?大家帮忙!rnDim conn As SqlConnectionrn Function GetSearchview() As DataViewrn Dim strvalue As String = Trim("txtSearchstring.text")rn If strvalue <> "" Thenrn strvalue = "%" & strvalue & "%"rn End Ifrn conn = New SqlConnection ("server=wiz02;uid=exam;pwd=exam;database=bookshop")rn Dim mycommand As SqlCommandrnrn Select Case SelCategory.SelectedItem.Valuern Case "title"rn mycommand = New SqlCommand("SearchByTitle", conn)rn mycommand.Parameters.Add(New SqlParameter("@title", SqlDbType.VarChar, 50))rn mycommand.Parameters("@title").Value = strvaluern Case "author"rn mycommand = New SqlCommand("SearchByAuthor", conn)rn mycommand.Parameters.Add(New SqlParameter("@author", SqlDbType.VarChar, 40))rn mycommand.Parameters("@author").Value = strvaluern Case "publisher"rn mycommand = New SqlCommand("SearchByPublisher", conn)rn mycommand.Parameters.Add(New SqlParameter("@publisher", SqlDbType.VarChar, 30))rn mycommand.Parameters("@publisher").Value = strvaluern End Selectrn mycommand.CommandType = CommandType.StoredProcedurern Dim ds As DataSetrn ds = New DataSet()rn Dim adapter As New SqlDataAdapter(mycommand)rn adapter.Fill(ds, "bookstore")rn If ds.Tables("bookstore").Rows.Count > 0 Thenrn Return (ds.Tables("bookstore").DefaultView)rn Elsern Return (Nothing)rn End Ifrn End Functionrn rn Sub data_bind(ByVal dview As DataView, ByVal bindobject As Object)rn bindobject.datasource = dviewrn bindobject.databind()rn End Subrnrn Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Clickrn Dim dview As DataView = GetSearchview()rn If dview.Count > 0 Thenrn lblResult.Text = "共找到" & dview.Count & "条记录."rn Elsern lblResult.Text = "对不起,没有找到符合条件的记录!"rn End Ifrn Session("Gridview") = dviewrn BookStore.CurrentPageIndex = 0rn data_bind(Session("Gridview"), BookStore)rn End Sub
相关热词 c# 标准差 计算 c#siki第五季 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池