我有了這個代碼...C#,「未將對象引用設置爲對象的實例」。錯誤
namespace YellowBox
{
public partial class Form1 : Form
{
private string sid = "";
FileTransferManager fm = new FileTransferManager();
Jid _jid = new Jid();
public Form1()
{
InitializeComponent();
fm.OnError += fm_OnError;
fm.OnEnd += fm_OnEnd;
fm.OnStart += fm_OnStart;
fm.OnProgress += fm_OnProgress;
}
private void btn_pickFile_Click(object sender, System.EventArgs e)
{
var of = new OpenFileDialog();
if (of.ShowDialog() == DialogResult.OK)
{
tb_file.Text = of.FileName;
var fi = new FileInfo(of.FileName);
//lblSize.Text = Util.HumanReadableFileSize(fi.Length);
btn_sendFile.Enabled = true;
}
}
private void btn_sendFile_Click(object sender, System.EventArgs e)
{
_jid.Server = "xxx";
_jid.User = "xxx"; /// EDIT, added the _jid values.
_jid.Resource = "xxx";
sid = fm.Send(_jid, tb_file.Text, ""); /// HERE IT SAYS "Object reference not set to an instance of an object." ???
btn_sendFile.Enabled = false;
btn_pickFile.Enabled = false;
}
...
而當我打的btn_sendFile它給了我一個「不設置到對象的實例對象引用。」錯誤。但是我在FileTransferManager中實例化了fm對象fm = new FileTransferManager(); ,不是嗎?
求助: 出現它丟失fm.XmppClient = xmppClient;
這可能是在抱怨'tb_file'。 – Oded 2011-03-11 15:37:10
在該行上設置一個斷點,並檢查哪個變量爲空。 – Blorgbeard 2011-03-11 15:37:11
放一個斷點,看看什麼是空的,不是? – 2011-03-11 15:37:36