Solved

Object reference not set to an instance of an object.

Posted on 2013-06-11
13
1,173 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Want to know why your HTC Droid DNA keeps turning on and off, or why it doesn’t seem to charge at all? This guide walks you through a laundry list of items to check to make sure you get the most out of your HTC Droid DNA.  Phone Will Not Turn On …
Having problems with your LG G3? Whether the front camera doesn’t work, the display doesn’t turn on, or your phone just doesn’t seem to be charging, you’ll be able to troubleshoot the issue with this step-by-step guide.  Phone doesn’t Charge It ta…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

19 Experts available now in Live!

Get 1:1 Help Now