【发布时间】:2019-10-28 18:48:34
【问题描述】:
我正在尝试阅读有关我在大学安排课程的 json 文件,从以下链接获取它:http://diag.uniroma1.it/pannello/?q=export_json
我尝试使用 https://developer.android.com/training/volley/simple 来实现它,它适用于非常简单的 json 文件,如 https://helloacm.com/api/factor/?cached&n=10 (给定一个数字,它返回自身的因式分解)。
但是应用相同的推理是行不通的。实际上,最初运行良好的应用程序现在崩溃了。
fun factors (x: String){
val queue = Volley.newRequestQueue(this)
//val url = "https://helloacm.com/api/factor/?cached&n="+x
val url = "http://diag.uniroma1.it/pannello/?q=export_json"
var reply : String = ""
// Request a string response from the provided URL.
val stringRequest = StringRequest(
Request.Method.GET, url,
Response.Listener<String> { response ->
// Display the first 500 characters of the response string.
reply = JSONObject(response.toString()).toString()
output.text=reply
},
Response.ErrorListener { error: VolleyError? -> output.text = error.toString() })
// Add the request to the RequestQueue.
queue.add(stringRequest)
}
有什么问题?文件太大了尊重前一个吗?我对这些东西真的很陌生
【问题讨论】:
-
你能分享崩溃日志吗?如果它崩溃了,我认为这与文件大小无关。可能还有其他一些 RuntimeException。
-
@Rachit 我在我的智能手机上运行它,当我按下按钮获得响应时,应用程序停止并出现:“application_name has stop Open app again”
-
您可以通过在手机上运行应用程序并转到 Android Studio 上的 Logcat 选项卡来检查崩溃日志。当崩溃发生时,您会看到崩溃的原因。
标签: android kotlin android-volley