Я сделал приложение, чтобы проверить, правильно ли введены имя пользователя и пароль, и если они верны, оно переходит к интерфейсу, в котором программа отображает данные пользователя, но при создании приложения ошибки нет, но при нажатии у кнопки логина ничего не происходит и получаю этот результат в терминале
Я хочу получить более одной переменной из базы данных mysql и использую php для печати json и библиотеки volley
V/AudioManager: playSoundEffect effectType: 0
querySoundEffectsEnabled...
D/HiTouch_PressGestureDetector: HiTouch on notch display, height corret:90
I/FLTAG_FM: loadFeature class:com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
I/FLTAG_SFM: getRequireClassLoader() succ ! className: com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
D/FeatureFactory: loadFeature() : com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
loadFeature() new IHwSplineOverScrollerEx()
D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl paras: android.widget.OverScroller$SplineOverScroller@55e6860,android.view.ContextThemeWrapper@73fe119
initSplineOverScrollerImpl: mScrollerVelocity is 0, value is 0
I/FLTAG_FM: loadFeature class:com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
I/FLTAG_SFM: getRequireClassLoader() succ ! className: com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
D/FeatureFactory: loadFeature() : com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
loadFeature() new IHwSplineOverScrollerEx()
D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl paras: android.widget.OverScroller$SplineOverScroller@6e475d5,android.view.ContextThemeWrapper@73fe119
initSplineOverScrollerImpl: mScrollerVelocity is 0, value is 0
I/FLTAG_FM: loadFeature class:com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
I/FLTAG_SFM: getRequireClassLoader() succ ! className: com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
D/FeatureFactory: loadFeature() : com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
loadFeature() new IHwSplineOverScrollerEx()
D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl paras: android.widget.OverScroller$SplineOverScroller@614e378,android.view.ContextThemeWrapper@73fe119
initSplineOverScrollerImpl: mScrollerVelocity is 0, value is 0
I/FLTAG_FM: loadFeature class:com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
I/FLTAG_SFM: getRequireClassLoader() succ ! className: com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
D/FeatureFactory: loadFeature() : com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx
loadFeature() new IHwSplineOverScrollerEx()
D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl paras: android.widget.OverScroller$SplineOverScroller@53392b6,android.view.ContextThemeWrapper@73fe119
initSplineOverScrollerImpl: mScrollerVelocity is 0, value is 0
D/OpenGLRenderer: HWUI Binary is enabled
I/HiTouch_HiTouchSensor: enabledInPad = false,isPcCastMode = false
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
I/ViewRootImpl: jank_removeInvalidNode all the node in jank list is out of time
D/OpenGLRenderer: HWUI Binary is enabled
W/libEGL: EGLNativeWindowType 0x71993e2010 disconnect failed
W/System.err: org.json.JSONException: No value for id_card
W/System.err: at org.json.JSONObject.get(JSONObject.java:392)
at org.json.JSONObject.getString(JSONObject.java:553)
at com.androidigniter.loginandregistration.LoginActivity$3.onResponse(LoginActivity.java:134)
at com.androidigniter.loginandregistration.LoginActivity$3.onResponse(LoginActivity.java:126)
at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:90)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:102)
at android.os.Handler.handleCallback(Handler.java:891)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:7539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
V/InputMethodManager: Reporting focus gain, without startInput
класс обработчика сеанса
package com.androidigniter.loginandregistration;
import android.content.Context;
import android.content.SharedPreferences;
import java.util.Date;
/**
* Created by AndroidIgniter on 23 Mar 2019 020.
*/
public class SessionHandler {
private static final String PREF_NAME = "UserSession";
private static final String KEY_USERNAME = "username";
private static final String KEY_EXPIRES = "expires";
private static final String KEY_FULL_NAME = "full_name";
private static final String KEY_EMAIL = "email";
private static final String KEY_COUNTRY = "country";
private static final String KEY_ID_CARD= "id_card";
private static final String KEY_EMPTY = "";
private Context mContext;
private SharedPreferences.Editor mEditor;
private SharedPreferences mPreferences;
public SessionHandler(Context mContext) {
this.mContext = mContext;
mPreferences = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
this.mEditor = mPreferences.edit();
}
/**
* Logs in the user by saving user details and setting session
*
* @param email
* @param username
* @param fullName
* @param country
* @param id_card
*
*
*/
public void loginUser( String username, String fullName, String email , String country , String id_card) {
mEditor.putString(KEY_USERNAME, username);
mEditor.putString(KEY_FULL_NAME, fullName);
mEditor.putString(KEY_EMAIL, email);
mEditor.putString(KEY_COUNTRY, country);
mEditor.putString(KEY_ID_CARD, id_card);
// mEditor.putString(KEY_EMAIL, card_id);
Date date = new Date();
//Set user session for next 7 days
long millis = date.getTime() + (7 * 24 * 60 * 60 * 1000);
mEditor.putLong(KEY_EXPIRES, millis);
mEditor.commit();
}
/**
* Checks whether user is logged in
*
* @return
*/
public boolean isLoggedIn() {
Date currentDate = new Date();
long millis = mPreferences.getLong(KEY_EXPIRES, 0);
/* If shared preferences does not have a value
then user is not logged in
*/
if (millis == 0) {
return false;
}
Date expiryDate = new Date(millis);
/* Check if session is expired by comparing
current date and Session expiry date
*/
return currentDate.before(expiryDate);
}
/**
* Fetches and returns user details
*
* @return user details
*/
public User getUserDetails() {
//Check if user is logged in first
if (!isLoggedIn()) {
return null;
}
User user = new User();
user.setUsername(mPreferences.getString(KEY_USERNAME, KEY_EMPTY));
user.setFullName(mPreferences.getString(KEY_FULL_NAME, KEY_EMPTY));
user.setEmail(mPreferences.getString(KEY_EMAIL, KEY_EMPTY));
user.setCountry(mPreferences.getString(KEY_COUNTRY, KEY_EMPTY));
user.setEmail(mPreferences.getString(KEY_ID_CARD, KEY_EMPTY));
user.setSessionExpiryDate(new Date(mPreferences.getLong(KEY_EXPIRES, 0)));
return user;
}
/**
* Logs out user by clearing the session
*/
public void logoutUser(){
mEditor.clear();
mEditor.commit();
}
}
логин
package com.androidigniter.loginandregistration;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import org.json.JSONException;
import org.json.JSONObject;
public class LoginActivity extends AppCompatActivity {
private static final String KEY_STATUS = "status";
private static final String KEY_MESSAGE = "message";
private static final String KEY_FULL_NAME = "full_name";
private static final String KEY_USERNAME = "username";
private static final String KEY_PASSWORD = "password";
private static final String KEY_COUNTRY = "country";
private static final String KEY_EMAIL = "email";
private static final String KEY_ID_CARD= "id_card";
private static final String KEY_EMPTY = "";
private EditText etUsername;
private EditText etPassword;
private String username;
private String password;
private String email;
private String country;
private String id_card;
private ProgressDialog pDialog;
private String login_url = "http://192.168.1.101/member/login.php";
private SessionHandler session;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
session = new SessionHandler(getApplicationContext());
if(session.isLoggedIn()){
loadDashboard();
}
setContentView(R.layout.activity_login);
etUsername = findViewById(R.id.etLoginUsername);
etPassword = findViewById(R.id.etLoginPassword);
Button register = findViewById(R.id.btnLoginRegister);
Button login = findViewById(R.id.btnLogin);
//Launch Registration sc-حححreen when Register Button is clicked
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(i);
finish();
}
});
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Retrieve the data entered in the edit texts
username = etUsername.getText().toString().toLowerCase().trim();
password = etPassword.getText().toString().trim();
if (validateInputs()) {
login();
}
}
});
}
/**
* Launch Dashboard Activity on Successful Login
*/
private void loadDashboard() {
Intent i = new Intent(getApplicationContext(), DashboardActivity.class);
startActivity(i);
finish();
}
/**
* Display Progress bar while Logging in
*/
private void displayLoader() {
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Logging In.. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
private void login() {
displayLoader();
JSONObject request = new JSONObject();
try {
//Populate the request parameters
request.put(KEY_USERNAME, username);
request.put(KEY_PASSWORD, password);
request.put(KEY_EMAIL, email);
request.put(KEY_COUNTRY, country);
request.put(KEY_ID_CARD, id_card);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsArrayRequest = new JsonObjectRequest
(Request.Method.POST, login_url, request, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
pDialog.dismiss();
try {
//Check if user got logged in successfully
if (response.getInt(KEY_STATUS) == 0) {
session.loginUser(username,email,response.getString(KEY_EMAIL),response.getString(KEY_COUNTRY),response.getString(KEY_ID_CARD));
//session.loginUser(username,response.getString(KEY_CARD_ID));
// session.loginUser(username,response.getString(KEY_ID_CON));
loadDashboard();
}else{
Toast.makeText(getApplicationContext(),
response.getString(KEY_MESSAGE), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pDialog.dismiss();
//Display error message whenever an error occurs
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(jsArrayRequest);
}
/**
* Validates inputs and shows error if any
* @return
*/
private boolean validateInputs() {
if(KEY_EMPTY.equals(username)){
etUsername.setError("Username cannot be empty");
etUsername.requestFocus();
return false;
}
if(KEY_EMPTY.equals(password)){
etPassword.setError("Password cannot be empty");
etPassword.requestFocus();
return false;
}
return true;
}
}