How do i fix 'type mismatch: inferred type is x but y was expected' in kotlin?

This error occurs when you're trying to assign a variable of one type to another incompatible type.

Example:


val number: Int = "123"

Solution:


val number: Int = "123".toInt()
Ensure that types are compatible or provide the necessary conversions.

Beginner's Guide to Kotlin