Solved

Object reference not set to an instance of an object.

Posted on 2013-06-11
13
1,235 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Is your Samsung Droid battery constantly dying? SIM card not connecting to your network? Is the display scrambling? This guide will walk you through a list of common Droid headaches and how to quickly solve them.  Poor Battery Life Your phone ba…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 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