AZZA-KHAMEES
asked on
Object reference not set to an instance of an object.
i created a sample project to try Jamaa SMPP, but when i run the code i am getting this error in the last line
please help
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);
}
please help
ASKER
thank you for the reply, yes so how can i solve it?
can u debug the code?
is the SmppClient client instance is null?
is the SmppClient client instance is null?
ASKER
fro where i can know if its null or not?
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:
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
}
}
ASKER
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 .SendMessa ge(ShortMe ssage masage)
which line?
ASKER
the error shows in line
which mean its pass the if statement
client.SendMessage(textMsg)
which mean its pass the if statement
try replace textMsg with string.Empty, is it still throwing exception?
ASKER
yes still
the problem is in the implementation of SendMessage function.
do u have the source of SmppClient ?
do u have the source of SmppClient ?
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window