Kotlin中的错误“类型不匹配”

时间:2018-07-04 00:27:33

标签: android python kotlin android-edittext type-mismatch

我有此类E_ex1Por,可用于连接Python中的服务。我需要该服务显示在editTextProverbio上。我下面的编码方式不起作用,并且给出了错误:type mismatch

    package com.example.asus.aprendecomigovelhinho

    import android.annotation.SuppressLint
    import android.content.Intent
    import android.support.v7.app.AppCompatActivity
    import android.os.Bundle
    import android.support.v7.widget.LinearLayoutManager
    import android.view.View
    import com.google.gson.GsonBuilder
    import kotlinx.android.synthetic.main.activity_d_lista.*
    import kotlinx.android.synthetic.main.activity_e_ex1_port.*
    import kotlinx.android.synthetic.main.activity_e_ex2_port.*
    import kotlinx.android.synthetic.main.activity_g_ex3_estmei.*
    import okhttp3.*
    import java.io.IOException

    class E_ex2Port: AppCompatActivity() {

        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_e_ex1_port)

            fetchJson()
        }

        fun fetchJson(){

           val url = "http://localhost:8080/portugues1/naoAutomatica/get"

            val request = Request.Builder().url(url).build()

            val client = OkHttpClient()
            client.newCall(request).enqueue(object : Callback {

                override fun onResponse(call: Call?, response: Response?) {
                    val body = response?.body()?.string()
                    println(body)

                    val gson = GsonBuilder().create()
                    val respProv = gson.fromJson(body, respostaProverbio::class.java

                    runOnUiThread {
                        editTextProverbio.text=respProv.proverbio.toString()
                    }
                }

                override fun onFailure(call: Call?, e: IOException?) {
                    println("Failed to execute request")
                }
            })
        }

    }
    class respostaProverbio(val proverbio: List<String> )

Python服务

    @route('/portugues2/naoAutomatica/get', method = "GET")
    def portugues2NaoAutomaticaGet():
        response.content_type = 'application/json;charset=utf-8'
        portugues2NaoAutomaticaGet = {  "proverbio": "Olhos que não vêem, coração que não sente"}
        return json.dumps(portugues2NaoAutomaticaGet)

建议改正?

0 个答案:

没有答案