【发布时间】:2015-11-18 08:34:57
【问题描述】:
我正在尝试按照在线教程创建此登录名,但收到此错误。我在本地主机上试过这个,但它在服务器上不起作用。谁能告诉我我的错误是什么。这是我的代码:
private void checkLogin(final String email, final String password) {
// Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Logging in ...");
showDialog();
StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_LOGIN, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Login Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
session.setLogin(true);
// Now store the user in SQLite
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user
.getString("created_at");
// Inserting row in users table
db.addUser(name, email, uid, created_at);
// Launch main activity
Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
【问题讨论】:
-
暂时注释掉onResponse里面的所有行,只留下
Log.d(TAG, "Login Response: " + response);然后发布你的新logcat信息 -
不是添加图片,而是添加有问题的日志。
-
在我注释完所有行之后,它就一直在登录。 Logcat: D/RegisterActivity: Login Response:
-
你的响应为空,没有收到任何字符串
-
你能告诉我我应该如何纠正这个问题吗?我已经在 localhost 上尝试过了,它成功了。
标签: java android json android-volley