A couple of months ago, I just started learning Java and Android programming. Faced a problem and in general I have no idea what could be the matter.

public void onClick(View v){ intent1 = createIntent("action 1", "extra 1"); pendingIntent1 = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT); intent2 = createIntent("action 2", "extra 2"); pendingIntent2 = PendingIntent.getBroadcast(this, 0, intent2, 0); sendNotif(101,pendingIntent1); sendNotif(201,pendingIntent2); } Intent createIntent(String action,String extra){ Intent intent = new Intent(this, MyReceiver.class); intent.setAction(action); intent.putExtra("extra",extra); return intent; } void sendNotif(int id,PendingIntent p){ Context context = getApplicationContext(); Notification.Builder builder = new Notification.Builder(context); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_launcher); builder .setAutoCancel(true) .setTicker("Тicker") .setContentText("Content"+id) .setContentTitle("Title"+id) .setProgress(100,20,true) .setDefaults(Notification.DEFAULT_ALL) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(largeIcon) .setContentIntent(p); Notification notification = builder.build(); // notification.flags = notification.flags|Notification.FLAG_INSISTENT; nm.notify(id,notification); } 

It is necessary to create two notifications, the sendNotif(int id, PendingIntent p) method sendNotif(int id, PendingIntent p) , in the event by pressing I create intents and pendingintants, and pass the latter as a parameter to my method, but an error crashes and the emulator just crashes.

Here are the pieces in Logcat, where I just sorted out these two rows:

  java.lang.IllegalStateException: Could not execute method of the activity Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.NotificationManager.notify(int, android.app.Notification)' on a null object reference 

As I understand from NullPointerException , it says that the second parameter passed to the notify method is not related to anything.

PS If you read all this, thank you very much for your minutes!

    0