Solved

Object reference not set to an instance of an object.

Posted on 2013-06-11
13
1,195 Views
Last Modified: 2013-06-13
i created a sample project to try Jamaa SMPP, but when i run the code i am getting this error in the last line
Object reference not set to an instance of an object.

protected void Page_Load(object sender, EventArgs e)
        {
            SmppClient client = new SmppClient();
            SmppConnectionProperties properties = client.Properties;
            properties.SystemID = "username";
            properties.Password = "password";
            properties.Port = 3333; 
            properties.Host = "xxx.xxx.xxx.xxx";
            properties.SystemType = "";
            properties.DefaultServiceType = "xxx";
      
            client.AutoReconnectDelay = 3000;

            client.KeepAliveInterval = 15000;

            client.Start();

            //--send SMS
            TextMessage textMsg = new TextMessage();
            textMsg.Text = "Hello, this is my message!";
            textMsg.DestinationAddress = "99999999";
            textMsg.SourceAddress = "888888888";
          
            client.SendMessage(textMsg);
        }

Open in new window


please help
0
Comment
Question by:AZZA-KHAMEES
  • 7
  • 6
13 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39240219
this line?
 client.SendMessage(textMsg);

Open in new window

0
 

Author Comment

by:AZZA-KHAMEES
ID: 39240282
thank you for the reply, yes so how can i solve it?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39240284
can u debug the code?
is the SmppClient client instance is null?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:AZZA-KHAMEES
ID: 39241216
fro where i can know if its null or not?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39241311
if you can debug the code and reproduce the exception every time then simply check if client is null.
also, u can add code which checks if the client is null.
i'd also use try/catch to detect what and where the error occur:
protected void Page_Load(object sender, EventArgs e)
        {try{
            SmppClient client = new SmppClient();
            SmppConnectionProperties properties = client.Properties;
            properties.SystemID = "username";
            properties.Password = "password";
            properties.Port = 3333; 
            properties.Host = "xxx.xxx.xxx.xxx";
            properties.SystemType = "";
            properties.DefaultServiceType = "xxx";
      
            client.AutoReconnectDelay = 3000;

            client.KeepAliveInterval = 15000;

            client.Start();

            //--send SMS
            TextMessage textMsg = new TextMessage();
            textMsg.Text = "Hello, this is my message!";
            textMsg.DestinationAddress = "99999999";
            textMsg.SourceAddress = "888888888";
          if(client != null){
            client.SendMessage(textMsg);
}else{
//log error to file or raise error
}
}catch(exception ex){
//log exception to file or raise error
}
        }

Open in new window

0
 

Author Comment

by:AZZA-KHAMEES
ID: 39243483
i tried your segusstion and i am getting the following error in catch

System.NullReferenceException: Object reference not set to an instance of object
at JamaaTech.Smpp.Net.Client.SmppClient.SendMessage(ShortMessage masage)
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39243559
which line?
0
 

Author Comment

by:AZZA-KHAMEES
ID: 39243607
the error shows in line
client.SendMessage(textMsg)

Open in new window


which mean its pass the if statement
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39243609
try replace textMsg with string.Empty, is it still throwing exception?
0
 

Author Comment

by:AZZA-KHAMEES
ID: 39243618
yes still
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39243628
the problem is in the implementation of SendMessage function.
do u have the source of SmppClient ?
0
 

Author Comment

by:AZZA-KHAMEES
ID: 39243692
SmppClient is dll file i download it from

CodePlex
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39243726
try use the 2nd SendMessage function where u pass timeout value:
client.SendMessage(textMsg, 1000);

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC identity 6 26
List<PaisEntity> - show some 1 22
transaction in asp.net, sql server 6 30
asp.net mvc5 6 12
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
Let Bitmoji into your life. Now is the time to learn a new language of smartphone messaging with this brief introduction.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now