Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Object reference not set to an instance of an object.

Posted on 2013-06-11
13
Medium Priority
?
1,270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 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