Error "Property must be initialized or be abstract" in Kotlin: causes and solutions
Hi! I started learning Kotlin and encountered an error that I can't fix. I'm writing a simple Android app, and I have a class where I declare several variables. The compiler gives an error: "Property must be initialized or be abstract". Here's my code:
```kotlin
class UserProfile {
var userName: String
var userAge: Int
var email: String
fun printInfo() {
println("Name: $userName, Age: $userAge, Email: $email")
}
}
```
I want these properties to be declared in the class, but without initial values, because they will be filled later, for example, after loading data from the database or after user input. In Java, I could just declare fields without initialization, and they would get default values (null for String, 0 for
No answers yet.
Log in to leave an answer
Blogs
using namespace std in C++: why it's bad and how it actually works
Rust won't compile on Windows? Solving the linker link.exe problem
Converting a string to a byte array in C#: a complete guide
PHP from Zero to Pro: Top YouTube Channels and Courses 2024