我正在做一個應用程序,我必須從CDMA手機發送短信,但它會引發空指針異常。我使用從CDMA發送短信(htc evo)拋出空指針異常
smsmanager.sendDataMessage(phonenumber, null, (short)1001, msgStr.getBytes(), sentPI, deliveredPI);
它拋出如下錯誤: -
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): FATAL EXCEPTION: main
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): java.lang.NullPointerException
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.os.Parcel.readException(Parcel.java:1253)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.os.Parcel.readException(Parcel.java:1235)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at com.android.internal.telephony.ISms$Stub$Proxy.sendData(ISms.java:558)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.telephony.SmsManager.sendDataMessage(SmsManager.java:524)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at prototype.smsonport.SmsOnPortActivity.sendSMS(SmsOnPortActivity.java:139)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at prototype.smsonport.SmsOnPortActivity.onClick(SmsOnPortActivity.java:38)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.view.View.performClick(View.java:2408)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.view.View$PerformClick.run(View.java:8817)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.os.Handler.handleCallback(Handler.java:587)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.os.Handler.dispatchMessage(Handler.java:92)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.os.Looper.loop(Looper.java:144)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at android.app.ActivityThread.main(ActivityThread.java:4937)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at java.lang.reflect.Method.invokeNative(Native Method)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at java.lang.reflect.Method.invoke(Method.java:521)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-21 14:53:26.875: ERROR/AndroidRuntime(8645): at dalvik.system.NativeStart.main(Native Method)
下面是函數
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent senDPI = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(SENT),
0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(
DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
short s = Short.parseShort(portStr);
short port = s;
Log.d("Data", "Sending SMS TO :: "+phonenumber);
Log.d("Data", "Sending SMS MESSAGE :: "+msgStr);
Log.d("Data", "Sending SMS on PORT :: "+port);
sms.sendDataMessage(phonenumber, null, port, msgStr.getBytes(), senDPI, deliveredPI);
所有PHONENUMBER,msgStr,港口來源於我的XML佈局文件的EDITTEXT領域。 我在這裏錯過了什麼? 幫助讚賞。
那一行代碼不足以診斷您的問題。你需要發佈更多的代碼。 – Squonk
在你的日誌中你有'toStr' - 是電話號碼嗎?如果是這樣,它從哪裏來的代碼?另外,'phonenumber'在'sendDataMessage(...)'的調用中來自哪裏? – Squonk
此外,來自API DEMO 8的SMS消息示例代碼也不適用於htc evo CDMA電話 – user755499