在 LoginActivity.java 中输入正确数据后,应用程序不会进入下一个活动,进度条不断加载,Logcat 向我显示此“登录”:[],“成功”:“0”,“消息”:“错误”当我在响应中使用Log.d时,看起来我插入了不正确的数据,但我确信它是正确的。我找不到问题出在哪里,我还在学习。
下面是一段代码:
private void Login(final String email, final String password){
loading.setVisibility(View.VISIBLE);
btn_login.setVisibility(View.GONE);
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_LOGIN,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
JSONArray jsonArray = jsonObject.getJSONArray("login");
if(success.equals("1")){
for (int i = 0; i < jsonArray.length(); i++){
JSONObject object = jsonArray.getJSONObject(i);
String name = object.getString("name").trim();
String email = object.getString("email").trim();
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
intent.putExtra("name", name);
intent.putExtra("email", email);
startActivity(intent);
loading.setVisibility(View.GONE);
}
}
} catch (JSONException e) {
e.printStackTrace();
loading.setVisibility(View.GONE);
btn_login.setVisibility(View.VISIBLE);
Toast.makeText(LoginActivity.this, "Error " +e.toString(),
Toast.LENGTH_SHORT).show();
}
Log.d(TAG, "Info" + response);
}
},
繁星淼淼
SMILET