I am trying to send SMS using a webservice call. But am having errors in doing so
This is the code snippet of what I am making use of
public void sendSMS(String from, String to, String msg) {
if (stat == -1) {
sms_url = username + "&password=" + password + "&from=" + from
+ "&to=" + to + "&message=" + msg + "";
new SendSMS().execute(sms_url);
}
}
private class SendSMS extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
for (String url : urls) {
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(
new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
result += s;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
@Override
protected void onPostExecute(String result) {
// textView.setText(result);
Intent intent = new Intent("com.sms.subsahara.CONFIRMACTIVITY");
startActivity(intent);
}
}
class PostService extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
Login();
Log.d(LOGTAG, "Success");
return "success";
}
@Override
protected void onPostExecute(String r) {
// TODO Auto-generated method stub
super.onPostExecute(result);
String msg = "Login successful";
if (MenuActivity.status == 2) {
Log.d(LOGTAG, result);
Log.d(LOGTAG, error + " " + uid + " " + langId + " " + rank);
} else if (SendUsing.status == 0) {
if (result.substring(0, 16).trim().equals(msg)) {
Log.d(LOGTAG, " " + "Connection Test" + result);
stat = -1;
String from = composesms.sender;
String to = composesms.phoneNo;
String message = composesms.message;
sendSMS(from, to, message);
Log.d(LOGTAG, result);
// new SendSMS().execute(params);
} else {
Toast.makeText(getBaseContext(),
"Login UnSuccesful. Check Username or password",
Toast.LENGTH_SHORT).show();
}
}
}
And on the submit Button, I have
public void onClick(View v) {
if (SendUsing.status == 0) {
new PostService().execute("success");
}
}
The Problem is when I do so, I get the following Exception
java.lang.IllegalStateException: Target host must not be null, or set in parameters.
at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:561)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:292)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
freed 4919 objects / 298512 bytes in 153ms
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
**at com.sms.subsahara.WebMessengerActivity$SendSMS.doInBackground(WebMessengerActivity.java:272)
at com.sms.subsahara.WebMessengerActivity$SendSMS.doInBackground(WebMessengerActivity.java:1)**
Please how do I solve this