I am trying to figure out how to send sms from my application. I have tried the following:
try {
String newNumber, newMessage;
newNumber = number.getText().toString();
newMessage = message.getText().toString();
smsManager.getDefault();
smsManager.sendTextMessage(newNumber, null, newMessage,null, null);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};thread.start();
But I get a log cat with this:
07-23 09:03:42.378: I/Process(14426): Sending signal. PID: 14426 SIG:
9 07-23 09:06:18.972: W/dalvikvm(14529): threadid=11: thread exiting
with uncaught exception (group=0x40a381f8) 07-23 09:06:18.972:
E/AndroidRuntime(14529): FATAL EXCEPTION: Thread-885 07-23
09:06:18.972: E/AndroidRuntime(14529): java.lang.NullPointerException
07-23 09:06:18.972: E/AndroidRuntime(14529): at
com.johnnydicamillo.sms.SmsSpammerActivity$1.run(SmsSpammerActivity.java:48)
07-23 09:06:19.238: W/IInputConnectionWrapper(14529): showStatusIcon
on inactive InputConnection 07-23 09:06:44.855: I/Process(14529):
Sending signal. PID: 14529 SIG: 9
It looks like
smsManagermay be null,getDefault()is a static method used to get the default instance of anSmsManagerand it doesn’t show that you are setting anything. You probably want that line to be something like: