gpt4 book ai didi

android - 应用程序返回空 toast

转载 作者:行者123 更新时间:2023-11-30 21:44:12 24 4
gpt4 key购买 nike

当我尝试将用户注册到我的 sql 数据库并且没有在 logcat 中抛出有用的错误提示时,我得到一个空的 Toast 作为响应。

请问这可能是什么原因造成的?

registerProcess

 private void registerProcess(final String name, final String email, final String password) {
// Tag used to cancel the request
String tag_string_req = "req_register";

pDialog.setMessage("Registering ...");
showDialog();

StringRequest strReq = new StringRequest(Request.Method.POST,
Functions.REGISTER_URL, new Response.Listener<String>() {

@Override
public void onResponse(String response) {
Log.d(TAG, "Register Response: " + response);
hideDialog();

try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
Functions logout = new Functions();
logout.logoutUser(getApplicationContext());

Bundle b = new Bundle();
b.putString("email", email);
Intent i = new Intent(RegisterActivity.this, EmailVerify.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtras(b);
startActivity(i);
pDialog.dismiss();
finish();

} else {
// Error occurred in registration. Get the error
// message
String errorMsg = jObj.getString("message");
Toast.makeText(getApplicationContext(),errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}

}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Registration Error: " + error.getMessage());
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {

@Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("name", name);
params.put("email", email);
params.put("password", password);

return params;
}

};

// Adding request to request queue
MyApplication.getInstance().addToRequestQueue(strReq, tag_string_req);
}

private void showDialog() {
if (!pDialog.isShowing())
pDialog.show();
}

private void hideDialog() {
if (pDialog.isShowing())
pDialog.dismiss();
}
}

网络服务

/**
* Adding new user to mysql database
* returns user details
*/

public function storeUser($fname, $lname, $email, $uname, $password) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$result = mysql_query("INSERT INTO users(unique_id, firstname, lastname, email, username, encrypted_password, salt, created_at) VALUES('$uuid', '$fname', '$lname', '$email', '$uname', '$encrypted_password', '$salt', NOW())");
// check for successful store
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM users WHERE uid = $uid");
// return user details
return mysql_fetch_array($result);
} else {
return false;
}
}

最佳答案

据我所见,代码似乎没有错误。您应该检查使用 curl 获得的响应并查看返回的内容。

关于android - 应用程序返回空 toast ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50213368/

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