gpt4 book ai didi

android - 注册 VOLLEY 和 KOTLIN 问题,有人能告诉我我遇到的问题是什么吗,错误 :

转载 作者:行者123 更新时间:2023-11-30 04:54:26 25 4
gpt4 key购买 nike

我正面临以下代码的错误有人可以帮帮我吗我正在尝试通过此代码注册到应用程序

注册 VOLLEY 和 KOTLIN 问题,有人能告诉我我遇到的错误是什么问题吗:

我正在添加这个以获取更多详细信息以发布我的问题

W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:111)


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

loading = findViewById<ProgressBar>(R.id.loading)
name = findViewById<EditText>(R.id.name)
email = findViewById<EditText>(R.id.email)
password = findViewById<EditText>(R.id.password)
c_password = findViewById<EditText>(R.id.password)
btn_regist = findViewById<Button>(R.id.btn_regist)

btn_regist.setOnClickListener() { v -> regist() }
}

private fun regist(){
loading.visibility = View.VISIBLE
btn_regist.visibility = View.GONE

val name:String = this.name.text.trim().toString()
val email:String = this.email.text.trim().toString()
val password:String = this.password.text.trim().toString()

val stringRequest = object : StringRequest(com.android.volley.Request.Method.POST, URL_REGIST,
com.android.volley.Response.Listener<String>() { response ->
try {
val jsonObject = JSONObject(response)
val success : String = jsonObject.getString("success")
if (success.equals("1")){
Toast.makeText(this, "Register Success ! Eyyvalll !", Toast.LENGTH_SHORT).show()
}
}
catch (e: JSONException){
e.printStackTrace()
Toast.makeText(this, "Register Error ! goh !!!! :/" + e.toString() , Toast.LENGTH_SHORT).show()
loading.visibility = View.GONE
btn_regist.visibility = View.VISIBLE

}
}, com.android.volley.Response.ErrorListener {
error -> error.printStackTrace()
Toast.makeText(this, "Register Error ! SHIT :/" + error.toString() , Toast.LENGTH_SHORT).show()
loading.visibility = View.GONE
btn_regist.visibility = View.VISIBLE
}) {
// @Throws(AuthFailureError::class)
override fun getParams(): Map<String, String> {
val params = HashMap<String, String>()
params["name"] = name
params["email"] = email
params["password"] = password
return params
}
}

val requestQueue = Volley.newRequestQueue(this)
requestQueue.add(stringRequest)

}`

最佳答案

我想到这个错误是因为响应结果不是有效的 json 格式

com.android.volley.Response.Listener<String>() { response ->
try {
//at this point,you can debug result with console log your response
//because if response have a php error then json format not valid
Log.d("RESPONSE"," $response")
val jsonObject = JSONObject(response)
//at this you can check if json has have key name success
if (jsonObject.has("success")){
val success : String = jsonObject.getString("success")
if (success.equals("1")){
Toast.makeText(this, "Register Success ! Eyyvalll !", Toast.LENGTH_SHORT).show()
}
}
}
......

希望对你有帮助

关于android - 注册 VOLLEY 和 KOTLIN 问题,有人能告诉我我遇到的问题是什么吗,错误 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59482550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com