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;

9
  • It is probably complaining aboutn tb_file. Commented Mar 11, 2011 at 15:37
  • 3
    Set a breakpoint on that line, and check which variable is null. Commented Mar 11, 2011 at 15:37
  • Put a breakpoint and see what is null, no ? Commented Mar 11, 2011 at 15:37
  • Where is tb_file initialized? Commented Mar 11, 2011 at 15:38
  • 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... Commented Mar 11, 2011 at 15:56

6 Answers 6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

THANKS EVERYBODY! Here's what appeared to be missing fm.XmppClient = xmppClient;
2

But what about your tb_file object.

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

3 Comments

never mind the tb_file, its a texbox, that gets its value assigned from tb_file.Text = of.FileName;
@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?
Did so, the trouble comes only from "sid = fm.Send(_jid, tb_file.Text, "myFile");"
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.

1 Comment

never mind the tb_file, its a texbox, that gets its value assigned from tb_file.Text = of.FileName;
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.

1 Comment

Did so, the trouble comes only from "sid = fm.Send(_jid, tb_file.Text, "myFile");"
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.

1 Comment

Based on your stack trace it's definately comnig from within your Matrix.Xmpp.Client.FileTransferManager object.
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.

1 Comment

Then something must be going on inside the method fm.Send. Can you able to step in and see.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.