Basically, the return value of getSystemService in this case is null. This is because you’re meant to pass in the class of the service that you want, not that MyClass, and so your code should become: getSystemService(requireContext(), NotificationManager::class.java) as NotificationManager
val notificationManager = activity?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
…
notificationManager.notify(NOTIFICATION_ID, builder.build())