2

I've got this code...

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;
        }

...

And when I hit the btn_sendFile it gives me a "Object reference not set to an instance of an object." error. But I had instanced the fm object in FileTransferManager fm = new FileTransferManager(); , didn't I?

SOLVED: Appears it was missing fm.XmppClient = xmppClient;

Roger
  • 6,443
  • 20
  • 61
  • 88
  • It is probably complaining aboutn `tb_file`. – Oded Mar 11 '11 at 15:37
  • 3
    Set a breakpoint on that line, and check which variable is null. – Blorgbeard Mar 11 '11 at 15:37
  • Put a breakpoint and see what is null, no ? – Julien Roncaglia Mar 11 '11 at 15:37
  • Where is tb_file initialized? – MattC Mar 11 '11 at 15:38
  • tb_file isn't null, its a texbox. yet _jib might be, as well as the last parameter "" , but it was the same way in the place I took it from and it worked there... – Roger Mar 11 '11 at 15:39
  • Is `FileTransferManager` a class in your project, or is it part of a separate dll? Also post the stack trace of the Exception. – Justin Mar 11 '11 at 15:40
  • @Roger - Please provide more information about `FileTransferManager`. Do you have the source of its `Send` method? If it is part of your project, the exception should be thrown *inside* that method (or a sub-method), assuming you are correct that `tb_file` is not null. – Justin Mar 11 '11 at 15:56
  • 1
    FileTransferManager comes from a separate dll. But I guess it loads fine, as if it wouldn't the error would come from instancing it... – Roger Mar 11 '11 at 15:56
  • THANKS EVERYBODY! Here's what appeared to be missing fm.XmppClient = xmppClient; – Roger Mar 11 '11 at 16:14

6 Answers6

2

But what about your tb_file object.

I dont see instantiation or definition of that object anywhere in your code.

Lav
  • 1,850
  • 15
  • 17
  • never mind the tb_file, its a texbox, that gets its value assigned from tb_file.Text = of.FileName; – Roger Mar 11 '11 at 15:46
  • @Roger I would recommend like others, adding try catch block around the line of code thats giving you trouble. That will help you pinpoint it. May be after that you can provide us with more informaiton about the exception? – Lav Mar 11 '11 at 15:55
  • Did so, the trouble comes only from "sid = fm.Send(_jid, tb_file.Text, "myFile");" – Roger Mar 11 '11 at 16:02
2

Reading your comments, i don't think any of the parameters you are passing to "Send" is null.

I Would say, there is a usability issue in the "FileTransferManager" class. It is possiby expecting something more from the user (something like, init,configure).

You will need to set breakpoint inside the FileTransferManager and then debug. No other choice.

Manish Basantani
  • 16,931
  • 22
  • 71
  • 103
1

Break point at the line and hover to see the value fm. Or tb_file.Text might be the one.

Other Check - Before calling sid = fm.Send(_jid, tb_file.Text, "");, can you print all the parameters and verify the values.

Kumar
  • 997
  • 5
  • 8
  • Then something must be going on inside the method `fm.Send`. Can you able to step in and see. – Kumar Mar 11 '11 at 16:11
1

Is it possible that the error is on tb_file.Text ?

There's no definition of this variable anywhere in the code. If this is the problem, you should also correct the assignation in the btn_pickFile_Click method.

krtek
  • 26,334
  • 5
  • 56
  • 84
  • never mind the tb_file, its a texbox, that gets its value assigned from tb_file.Text = of.FileName; – Roger Mar 11 '11 at 15:47
1

Can you debug the application and set a breakpoint on the line of code that is throwing the exception. Hover you mouse over each object on that line and it will show you which one is null. That will let you know where the problem is, after that it is a matter of figuring out why it is null. I cant tell anything more from the code you have posted.

SecretDeveloper
  • 3,140
  • 2
  • 31
  • 36
1

Probably wise to stick a try..catch block around the sid = fm.Send(_jid, tb_file.Text, ""); call snd then in the catch you will be able to see the stack trace which should tell you where the exception is orginating.

It could be being generated from inside you FileTransferManager class.

MattC
  • 3,984
  • 1
  • 33
  • 49
  • Based on your stack trace it's definately comnig from within your Matrix.Xmpp.Client.FileTransferManager object. – MattC Mar 11 '11 at 16:10