我使用此代码 (GCMIntentService.java) 来解码从 GCM 收到的消息:
String message = intent.getStringExtra("message"); // works fine.
try {
message = URLDecoder.decode(message, "UTF-8"); // decode fine, but get the error below.
} catch (UnsupportedEncodingException e1) {
throw new AssertionError("UTF-8 is unknown");
}
收到的消息与发送(编码)的消息相同。对于编码,我使用这个:
String message = URLEncoder.encode(items[0].getMessage(),"UTF-8"); // works fine
我得到这个错误,我找不到空指针异常的原因。
07-19 17:33:44.687: E/AndroidRuntime(21742): FATAL EXCEPTION: IntentService[GCMIntentService-0002223333444-2]
07-19 17:33:44.687: E/AndroidRuntime(21742): java.lang.NullPointerException
07-19 17:33:44.687: E/AndroidRuntime(21742): at com.chat.ak.GCMIntentService.onMessage(GCMIntentService.java:70)
07-19 17:33:44.687: E/AndroidRuntime(21742): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
07-19 17:33:44.687: E/AndroidRuntime(21742): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
07-19 17:33:44.687: E/AndroidRuntime(21742): at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 17:33:44.687: E/AndroidRuntime(21742): at android.os.Looper.loop(Looper.java:130)
07-19 17:33:44.687: E/AndroidRuntime(21742): at android.os.HandlerThread.run(HandlerThread.java:60)
非常感谢您提前。