开发者

Why do I get NullPointerException when sending an SMS on an HTC Desire, or what is SubmitPdu?

开发者 https://www.devze.com 2023-02-02 17:51 出处:网络
So I get this stack trace: java.lang.NullPointerException at android.telephony.SmsMessage$SubmitPdu.<init>(SmsMessage.java:132)

So I get this stack trace:

java.lang.NullPointerException    
   at android.telephony.SmsMessage$SubmitPdu.<init>(SmsMessage.java:132)
   at android.telephony.SmsMessage.getSubmitPdu(SmsMessage.java:551)
   at android.telephony.SmsMan开发者_开发技巧ager.sendTextMessage(SmsManager.java:228)
   at android.telephony.SmsManager.sendTextMessage(SmsManager.java:107)
   at com.emergency.button.SMSSender.safeSendSMS(SMSSender.java:91)
   at com.emergency.button.EmergencyActivity$EmergencyThread
       .sendSMS(EmergencyActivity.java:294)
   at com.emergency.button.EmergencyActivity$EmergencyThread
       .sendMessages(EmergencyActivity.java:386)
   at com.emergency.button.EmergencyActivity$EmergencyThread
       .run(EmergencyActivity.java:266)

And this is how I call sendTextMessage, I don't verify message length or phone number validity:

sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);

This error seems to only occur on HTC Desire or HTC Wildfire with android version 2.2 or 2.21 so I dug up the android platform source (which is actually not as easy to do as I expected) and found:

SmsMessage.java once upon a time though this might not be relevant as I see some of the line numbers don't line up.

The emergency button project is open source so you can check the code out for reference. I should probably note that I can't test this myself, I don't have either phone model.


You might be hitting this issue with a message that is too long. I don't know why it would only be happening for certain phones, though.

http://code.google.com/p/android/issues/detail?id=3718


Replace

sms.sendDataMessage(destinationAddress, scAddress, destinationPort, data, sentIntent, deliveryIntent)

by

sms.sendMultipartTextMessage(phoneNumber, null, message, null, null);

Your message must be an ArrayList for that, use this method before calling sendSMS

SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(locationMessage);
sendSMS(telNumber.getText().toString(),parts );


Not an answer but too long to post in a comment...

I think you may have multiple problems - no idea what this might mean to you but I had my desire hooked up to DDMS and gave it a try. The SMS and email were sent without problem (no errors on the stack trace) but this is what I got when using the BACK button from the Activity that shows progress (waiting for location, email sent, SMS sent etc).

01-03 02:57:11.335: ERROR/ActivityThread(14514): Activity com.emergency.button.EmergencyActivity has leaked IntentReceiver com.emergency.button.SMSSender$3@4628f068 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-03 02:57:11.335: ERROR/ActivityThread(14514): android.app.IntentReceiverLeaked: Activity com.emergency.button.EmergencyActivity has leaked IntentReceiver com.emergency.button.SMSSender$3@4628f068 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:972)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:755)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:799)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:786)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:780)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at com.emergency.button.SMSSender.safeSendSMS(SMSSender.java:75)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at com.emergency.button.EmergencyActivity$EmergencyThread.sendSMS(EmergencyActivity.java:294)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at com.emergency.button.EmergencyActivity$EmergencyThread.sendMessages(EmergencyActivity.java:386)
01-03 02:57:11.335: ERROR/ActivityThread(14514):     at com.emergency.button.EmergencyActivity$EmergencyThread.run(EmergencyActivity.java:266)
01-03 02:57:11.345: ERROR/ActivityThread(14514): Activity com.emergency.button.EmergencyActivity has leaked IntentReceiver com.emergency.button.SMSSender$2@462b1e88 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-03 02:57:11.345: ERROR/ActivityThread(14514): android.app.IntentReceiverLeaked: Activity com.emergency.button.EmergencyActivity has leaked IntentReceiver com.emergency.button.SMSSender$2@462b1e88 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:972)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:755)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:799)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:786)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:780)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at com.emergency.button.SMSSender.safeSendSMS(SMSSender.java:50)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at com.emergency.button.EmergencyActivity$EmergencyThread.sendSMS(EmergencyActivity.java:294)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at com.emergency.button.EmergencyActivity$EmergencyThread.sendMessages(EmergencyActivity.java:386)
01-03 02:57:11.345: ERROR/ActivityThread(14514):     at com.emergency.button.EmergencyActivity$EmergencyThread.run(EmergencyActivity.java:266)


You have to unregister sms sent intent reciever and sms delivered intent after use, One thing you can do declare the intent Receivers as seperate class which extends BraodCast, Then you can unregister the receivers.

0

精彩评论

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