【发布时间】:2021-09-09 18:34:31
【问题描述】:
我正在尝试构建一个天气应用程序,这是我第一次使用和 api 所以我从文档开始,但仍然没有得到回应
fun getWeather(view:View){
val city = cityName.text.toString()
cityName.text.clear()
//val url = "api.openweathermap.org/data/2.5/weather?q=$city&appid=cb8d284902f295b8759aa295cb6bafc3"
val url = "https://www.google.com"
val queue = Volley.newRequestQueue(this)
val stringRequest = StringRequest(Request.Method.GET,url, Response.Listener<String> {
response ->
weatherResult.text = "it worked" + response.substring(0,10)
},Response.ErrorListener {
weatherResult.text = "there was an error"
})
queue.add(stringRequest)
}
【问题讨论】:
-
我必须使用“url”的值,因为我尝试了第一个,它给了我一个错误响应
-
使用 printStackTrace() 查看错误并使用堆栈跟踪编辑您的问题。
标签: android android-studio kotlin android-volley android-api-levels