我正在尝试使用Java代码发送SMS。我发送英文短信时效果很好。但是当我尝试下面给出的俄语信息时失败。抛出NullPointerException

String message = "Здравствуйтe, сейчас я не могу ответить на Ваш звонок.  Перезвоните через 10 минут, если Вам не ответили. Спасибо";
PendingIntent pi = PendingIntent.getActivity(this, 0,
    new Intent(this, RussianSmsProblemActivity.class), 0);
SmsManager sms = SmsManager.getDefault();

sms.sendTextMessage("5556", null, message,sentPI,deliveredPI);//getting Null Pointer Exception here


代码没有问题,NullpointerException包含在Android API中。请一些专家对此问题进行指导。

这是异常堆栈跟踪...

  12-15 16:48:32.994: ERROR/AndroidRuntime(347): FATAL EXCEPTION: main
  12-15 16:48:32.994: ERROR/AndroidRuntime(347): java.lang.NullPointerException
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.os.Parcel.readException(Parcel.java:1328)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.os.Parcel.readException(Parcel.java:1276)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:369)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.telephony.gsm.SmsManager.sendTextMessage(SmsManager.java:79)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at com.test.RussianSmsProblemActivity.sendSms(RussianSmsProblemActivity.java:102)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at com.test.RussianSmsProblemActivity$1.onClick(RussianSmsProblemActivity.java:39)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.view.View.performClick(View.java:2485)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.view.View$PerformClick.run(View.java:9080)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.os.Handler.handleCallback(Handler.java:587)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.os.Handler.dispatchMessage(Handler.java:92)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.os.Looper.loop(Looper.java:123)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at java.lang.reflect.Method.invoke(Method.java:507)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  12-15 16:48:32.994: ERROR/AndroidRuntime(347):     at dalvik.system.NativeStart.main(Native Method)

最佳答案

我认为这是因为俄语字符在UTF-8中消耗了2个字节。因此,消息超出了160字节限制。尝试使用sendMultiPartMessage()代替。

10-07 16:29
查看更多