I am unsure what the error message is (see below) and why I am getting it.
fun safeUserInput():Char{
var input = ""
var correctInput = false
while (correctInput){
println("Please, input your guess.")
input = safeReadLine()
if (input!=null&&input.isNotEmpty()) {
correctInput = isCorrectInput(input)
}
}
return input.first().uppercaseChar()
}
fun isCorrectInput(guess: String):Boolean{
if (guess.length!=1){
println("The length of your guess should be 1! Try again.")
return false
}
if (!guess.first().isLetter() ){
println("You should input only English letters! Try again.")
return false
}
return true
}
Char sequence is empty.
java.util.NoSuchElementException: Char sequence is empty.
at kotlin.text.StringsKt___StringsKt.first(_Strings.kt:72)
at MainKt.safeUserInput(Main.kt:29)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.jetbrains.academy.test.system.MethodUtilsKt.invokeWithArgs(MethodUtils.kt:22)
at org.jetbrains.academy.test.system.MethodUtilsKt.invokeWithoutArgs(MethodUtils.kt:10)
at org.jetbrains.academy.test.system.MethodUtilsKt.invokeWithoutArgs$default(MethodUtils.kt:6)
at Test.testSafeUserInputImplementation(Tests.kt:88)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
(etc...)
educational_plugin FAILED + Char sequence is empty.
Test > testSolution() FAILED
java.util.NoSuchElementException at Tests.kt:133
educational_plugin FAILED + Char sequence is empty.
Test > testGameImitation() FAILED
java.util.NoSuchElementException at Tests.kt:141
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[1] FAILED
java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[2] FAILED
java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[3] FAILED
java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[4] FAILED
java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[5] FAILED
java.util.NoSuchElementException at Tests.kt:88
25 tests completed, 7 failed
FAILURE: Build failed with an exception.
I am unsure what the error message is (see below) and why I am getting it.
fun safeUserInput():Char{ var input = "" var correctInput = false while (correctInput){ println("Please, input your guess.") input = safeReadLine() if (input!=null&&input.isNotEmpty()) { correctInput = isCorrectInput(input) } } return input.first().uppercaseChar() }
fun isCorrectInput(guess: String):Boolean{ if (guess.length!=1){ println("The length of your guess should be 1! Try again.") return false } if (!guess.first().isLetter() ){ println("You should input only English letters! Try again.") return false } return true } Char sequence is empty. java.util.NoSuchElementException: Char sequence is empty. at kotlin.text.StringsKt___StringsKt.first(_Strings.kt:72) at MainKt.safeUserInput(Main.kt:29) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at org.jetbrains.academy.test.system.MethodUtilsKt.invokeWithArgs(MethodUtils.kt:22) at org.jetbrains.academy.test.system.MethodUtilsKt.invokeWithoutArgs(MethodUtils.kt:10) at org.jetbrains.academy.test.system.MethodUtilsKt.invokeWithoutArgs$default(MethodUtils.kt:6) at Test.testSafeUserInputImplementation(Tests.kt:88) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) (etc...)
educational_plugin FAILED + Char sequence is empty.
Test > testSolution() FAILED java.util.NoSuchElementException at Tests.kt:133
educational_plugin FAILED + Char sequence is empty.
Test > testGameImitation() FAILED java.util.NoSuchElementException at Tests.kt:141
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[1] FAILED java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[2] FAILED java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[3] FAILED java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[4] FAILED java.util.NoSuchElementException at Tests.kt:88
educational_plugin FAILED + Char sequence is empty.
Test > testSafeUserInputImplementation(List, char) > Test.testSafeUserInputImplementation(List, char)[5] FAILED java.util.NoSuchElementException at Tests.kt:88 25 tests completed, 7 failed FAILURE: Build failed with an exception.