为什么在我尝试回复通知时收到NullPointerException

时间:2019-07-02 08:37:23

标签: android bundle

当我尝试回复通知时出现错误。但是我只能在具有API 24的穿戴式设备上遇到错误。在移动设备上,它可以正常工作而没有错误。

我得到的错误: Unable to start receiver com.github.nkzawa.socketio.androidchat.NotificationBroadcastReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.BaseBundle.getString(java.lang.String)'

public void onReceive(Context context, Intent replyIntent) {

    Bundle remoteInput = RemoteInput.getResultsFromIntent(replyIntent);

    String replyMessage = remoteInput.getCharSequence(SocketService.KEY_TEXT_REPLY).toString().trim();

1 个答案:

答案 0 :(得分:0)

错误可能是您正在使用外部库,并且该库仅适用于Android设备,不适用于穿戴式设备。这就是我认为的错误所在。您的代码看起来不错。但是我不知道是否缺少任何依赖关系,或者您的getApplicationContext()在穿戴设备中是否返回任何内容。