The problem encountered during the test yesterday afternoon was solved this morning. The error code is as follows:
String phone = dbHelper. getPhoneByTime (timeString); SmsManager sms = SmsManager. getDefault (); Intent sentIntent = new Intent (Const. SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent. getBroadcast (this, 0, sentIntent, 0); // create the deilverIntent parameterIntent deliverIntent = new Intent (Const. DELIVERED_SMS_ACTION); PendingIntent deliverPI = PendingIntent. getBroadcast (this, 0, deliverIntent, 0); sms. sendTextMessage (phone, null, msg, sentPI, deliverPI); // send
A null pointer exception is always reported in this row. The first response is that the variable has not been initialized and has been checked several times,
The mobile phone number is read from the database, msg is generated automatically, and sentPI and deliverPI are both good,
There is indeed no NULL pointer. You can find it again ..
I realized this morning that the length of the text message was incorrect.
The length of a text message is 70 characters. I counted it. It turns out that the content to be sent is too long.
Change to the following:
if (message.length() > 70) {ArrayList
msgs = sms.divideMessage(message);for (String msg : msgs) {if (msg != null) {sms.sendTextMessage(phone, null, msg, sentPI,deliverPI);}}} else {sms.sendTextMessage(phone, null, message, sentPI, deliverPI);}
Determine the length of the text message. If the length is too long, it can be divided into multiple messages.
I cannot understand why a null pointer is reported when the text message is too long.
Author: jason0539
Weibo: http://weibo.com/2553717707
Blog: http://blog.csdn.net/jason0539 (reprinted please explain the source)