I have this code
var str : CharArray
var t =0
for (k in i..i+3) {
str[t++] = array[k][j]
and it says str must be initialized, i don't know how to initialize.
I tried to initialize like this, but it says type mismatch,
var array: Array<CharArray> = arrayOf("India");
Type inference failed. Expected type mismatch: required: Array found: Array
You can initialize it this way:
var str : CharArray = CharArray(3) //if you know size
var str : CharArray = charArrayOf() //creates empty array
var str : CharArray? = null //makes your array nullable
Or you can use lateinit
for initializing later
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With