开发者

SmsManager NullPointer Exception. Confused... so simple, should work

开发者 https://www.devze.com 2023-04-05 06:21 出处:网络
If I send the following. SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(\"2064035760\", null, \"Message\", null, null);

If I send the following.

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("2064035760", null, "Message", null, null);

It throws the following exception.

I have the proper permissions.

java.lang.NullPointerException
    at android.telephony.SmsMessage$SubmitPdu. (SmsMessage.java:140)
    at android.telephony.SmsMessage.getSubmitPdu(SmsMessage.java:624)
    at android.telephony.SmsManager.sendTextMessage(SmsManager.java:228)
    at android.telephony.SmsManager.sendTextMessage(SmsManager.java:109)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Th开发者_高级运维readPoolExecutor.java:581)
    at java.lang.Thread.run(Thread.java:1027)


See this question. Have you tried using sendMultipartTextMessage? It seems that if the message is too long it will throw a NullPointerException (why I don't know). I realize your message only says "Message", but it is worth a try.

0

精彩评论

暂无评论...
验证码 换一张
取 消