Q:

Android Toast Messages are not shown using Fuel Framework

I am using Fuel to send and receive requests from an API.
However, I am not able to show Toast Messages or AlertDialogs, if the request was not successful.
Sample Code:
private fun validatePassword(): Boolean {
    var minPasswordLength = 0
    val password = findViewById<EditText>(R.id.input_password_register).text.toString()
    val password_repeat: String = findViewById<EditText>(R.id.input_password_repeat_register).text.toString()

    "/auth/password.json".httpGet().responseString { request, response, result ->
        //do something with response
        request.header(mapOf("Content-Type" to "application/json"))
        Log.println(Log.ASSERT, "password_Curl", request.cUrlString())

        when (result) {
            is Result.Failure -> {
                val data = response.data.toString(Charsets.UTF_8)
                Log.println(Log.ASSERT, "Response_Password_Fail", data)

                val jelement = JsonParser().parse(data)
                val jobject = jelement.asJsonObject

                Toast.makeText(this, jobject.get("Error").asString, Toast.LENGTH_SHORT).show()
            }
            is Result.Success -> {
                val data = response.data.toString(Charsets.UTF_8)
                Log.println(Log.ASSERT, "Response_Passwd_Succes", data)

                val jelement = JsonParser().parse(data)
                val jobject = jelement.asJsonObject

                minPasswordLength = jobject.get("minimal_length").asInt
            }
        }
    }
    return password.length >= minPasswordLength && password.equals(password_repeat)
}

I have tried to run the makeText command on the UIThread using:
runOnUiThread{Toast.makeText(this, jobject.get("Error").asString, Toast.LENGTH_SHORT).show()}

This did not work either.
I do however get to the code while debugging:

Thanks for the help! Cheers.
UPDATE: 
While debugging I noticed that minPasswordLength stays 0 even though "minimal_length" from the API has the value 8. So maybe it is a Threading problem?

A:

Use the implementation 'com.github.kittinunf.fuel:fuel-android:1.15.0 instead of implementation 'com.github.kittinunf.fuel:fuel:1.15.0' in the dependencies (build.gradle file).
The JVM implementation of the library doesn't automatically invoke the handlers in the UI thread.

This works for me even in the JVM implementation:
runOnUiThread { Toast.makeText(this, "Some text", Toast.LENGTH_SHORT).show() }
I think that it didn't work for you because the JSON doesn't contain the "Error" but "details" field.

