+ 1
[SOLVED] Please, could someone help! What's the problem here?
7 Réponses
+ 5
Ipang , I think your'e wrong.
The NOT-null assertion operator (!!) converts any value to a NON-null type!
That's, why the interpreter can be sure, that this value never can be NULL.
So if you use this:
var word = readLine()!!
with an empty input (=null), the interpreter throws an exception. It's not possible, but null-save for the whole prog.
Or, you use it null-able like this:
var word = readLine()
Now you are able to make an empty input (=null) . But every time, you want to access this variable, you have to check it against NULL by your self, like this:
fun main(args: Array<String>) {
var word = readLine()
if (word != null) {
for(x in word) {
println(x)
}
}
}
+ 5
Line 2:
Non-nullable input for variable <var>
Add !! to make it nullable
var word = readLine()!!
+ 3
It works but why I must make it nullable? Ipang
+ 3
I saw this message before I added the !!
"error: not nullable value
required to call an 'iterator()"' method on for-loop range
for(x in word){"
I thought about just adding those !!
And it turned out to be working, so I suggested you that also ...
+ 3
Thank you for better insight Coding Cat 🙏
+ 2
Thanks a lot Coding Cat [Mouse searching]
Your code is also working :)