PendingIntent
を取得しようとしていますが、通知ドロワーのnotification
をクリックするたびにアプリケーションがクラッシュします。通知バー(PendingIntent)で通知がクリックされた後のNullPointerException
だから、基本的に、私はCustomerCurrentlyServing.class、それがロードされたとき、それは前のアクティビティから渡されたすべての文字列を取得すると呼ばれるこのJavaクラスを以下に示しているよう:
queueNo = String.valueOf(getIntent().getExtras().getInt(Constants.EX_MSG_QUEUE_NO));
queueKey = getIntent().getExtras().getString(Constants.EX_MSG_QUEUE_KEY);
shopName = getIntent().getExtras().getString(Constants.EX_MSG_SHOP_NAME);
shopKey = getIntent().getExtras().getString(Constants.EX_MSG_SHOP_KEY);
customerid = getIntent().getExtras().getString(Constants.EX_MSG_CUSTOMER_ID);
は私がする方法を実装しました
public void showNotification() {
Intent intent = new Intent(getApplicationContext(), CustomerCurrentServing.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, CustomerCurrentServing.class), 0);intent.putExtra(Constants.EX_MSG_QUEUE_NO,queueNo);
intent.putExtra(Constants.EX_MSG_QUEUE_NO,queueNo);
intent.putExtra(Constants.EX_MSG_QUEUE_KEY,queueKey);
intent.putExtra(Constants.EX_MSG_SHOP_NAME,shopName);
intent.putExtra(Constants.EX_MSG_SHOP_KEY,shopKey);
Resources r = getResources();
Notification notification = new NotificationCompat.Builder(this)
.setTicker(r.getString(R.string.notification_title))
.setSmallIcon(android.R.drawable.ic_menu_report_image)
.setContentTitle(r.getString(R.string.notification_title))
.setContentText(r.getString(R.string.notification_text))
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
ユーザが通知ドロワーの通知をクリックすると、基本的に同じクラスが開きます。このエラーを解決する方法を
queueNo = String.valueOf(getIntent().getExtras().getInt(Constants.EX_MSG_QUEUE_NO));
任意のアイデア:しかし、それは私が通知をクリックすると、エラーがライン上NullPointerExceptionがある時はいつでもクラッシュしますか?私はこのエラーを1週間解決しようとしていて、あなたの助けに感謝しています。
'PendingIntent.getActivity()'に渡す 'Intent'に追加項目を追加する必要があります。そして**あなたが 'PendingIntent.getActivity()'を呼び出す前に**それらを追加する必要があります。小さな太陽からの答えを見てください。 –