"-6ren">
gpt4 book ai didi

java - println 在 android 中需要一条消息

转载 作者:行者123 更新时间:2023-11-30 03:04:05 25 4
gpt4 key购买 nike

在我的谷歌云消息应用程序中。它显示错误为空指针异常:println 需要 android 中的消息 e。我试图更改代码:

Log.e("UnRegister Receiver Error", "> " + e.getMessage());

到:

String err = (e.getMessage()==null)?"UnRegister Receiver Error":e.getMessage();
Log.e("UnRegister Receiver Error", err);

但它仍然是同样的错误。请帮助我。

@Override
protected void onDestroy() {
if (mRegisterTask != null) {
mRegisterTask.cancel(true);

}
try {
unregisterReceiver(mHandleMessageReceiver);
GCMRegistrar.onDestroy(this);
} catch (Exception e) {

//String err = (e.getMessage()==null)?"UnRegister Receiver Error":e.getMessage();
//Log.e("UnRegister Receiver Error", err);
Log.e("UnRegister Receiver Error", "> " + e.getMessage());
}

super.onDestroy();
}

日志:

02-28 22:58:35.254: E/AndroidRuntime(2812): FATAL EXCEPTION: IntentService[GCMIntentService-414538748674-1]
02-28 22:58:35.254: E/AndroidRuntime(2812): java.lang.NullPointerException: println needs a message
02-28 22:58:35.254: E/AndroidRuntime(2812): at android.util.Log.println_native(Native Method)
02-28 22:58:35.254: E/AndroidRuntime(2812): at android.util.Log.d(Log.java:138)
02-28 22:58:35.254: E/AndroidRuntime(2812): at com.example.fitness2.GCMIntentService.onRegistered(GCMIntentService.java:29)
02-28 22:58:35.254: E/AndroidRuntime(2812): at com.google.android.gcm.GCMBaseIntentService.handleRegistration(GCMBaseIntentService.java:296)
02-28 22:58:35.254: E/AndroidRuntime(2812): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:197)
02-28 22:58:35.254: E/AndroidRuntime(2812): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
02-28 22:58:35.254: E/AndroidRuntime(2812): at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 22:58:35.254: E/AndroidRuntime(2812): at android.os.Looper.loop(Looper.java:137)
02-28 22:58:35.254: E/AndroidRuntime(2812): at android.os.HandlerThread.run(HandlerThread.java:60)
02-28 22:58:35.422: W/EGL_emulation(2812): eglSurfaceAttrib not implemented
02-28 22:58:35.774: V/GCMRegistrar(2812): Unregistering receiver
02-28 22:58:35.774: E/UnRegister Receiver Error(2812): Receiver not registered: com.google.android.gcm.GCMBroadcastReceiver@5342460c
02-28 22:58:35.774: E/UnRegister Receiver Error(2812): > Receiver not registered: com.google.android.gcm.GCMBroadcastReceiver@5342460c

最佳答案

您不必手动打印它。您可以使用 printStackTrace 执行此操作,如下所示

e.printStackTrace ();

您所要做的就是用这一行替换所有 catch 代码。

您尝试注销尚未注册的广播接收器的 logcat 天数。 (阅读最后两行)我想你一开始忘了调用 register receiver 。

关于java - println 在 android 中需要一条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22107373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com