What causes 'null can not be a value of a non-null type string' in kotlin?

Example:

var name: String = null

By default, Kotlin types are non-nullable. This error is raised when you try to assign null to a non-nullable type.

Solution:

If you want your variable to be nullable, declare it with a '?' suffix.


var name: String? = null

Beginner's Guide to Kotlin