0
I am consuming an API and called Broadcastreceiver whenever the user connects to the internet. However, when displaying the notification is appearing:
"java.lang.Nullpointerexception: Attempt to invoke virtual method 'android.content.Contentresolver android.content.Context.getContentResolver()' on a null Object Reference"
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,CHANNEL_ID);
builder.setSmallIcon(R.drawable.ic_tem_pedido);
builder.setContentTitle("Novo Pedido !");
builder.setContentText("Favor, verificar o sistema !");
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
builder.setDefaults(
NotificationCompat.DEFAULT_VIBRATE
);
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse("https:www.google.com"));
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this,
0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.ic_visitar_site,"Visitar site",pi);
NotificationManagerCompat notificationManagerCompat =
NotificationManagerCompat.from(this);
notificationManagerCompat.notify(NOTIFICATION_ID,builder.build());
In this line:
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this,
0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Are you using this code where? In a separate class or on Main ?
– Andrei Coelho
The problem is that the context
MainActivity.this
is void!– Andrei Coelho