когда я размещаю свое имя пользователя и пароль на странице входа. тогда я получил ответ API, но моя активность на панели не открыта. я получаю W / System.err: org.json.JSONException: нет значения для ошибки электронной почты в моем параметре API. Когда я удаляю параметр электронной почты, эта ошибка переходит к следующему параметру. А что я могу сделать
? нужна помощь
Я много раз пытался войти в систему, этот ответ API работает, но активность не открыта.
LoginModel.java
package com.tsa.nccapp.models;
/**
* Created by hp on 31-Dec-2018.
*/
public class LoginModel {
private String regiment_number;
private String rank;
private String name_of_cadet;
private String email;
private String mobile;
private String father_name;
private String exam_type;
private String unit;
private String ncc_group;
private String state;
private String district;
private String town;
private String directorate;
private String membership_status;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName_of_cadet() {
return name_of_cadet;
}
public void setName_of_cadet(String name_of_cadet) {
this.name_of_cadet = name_of_cadet;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getFather_name() {
return father_name;
}
public void setFather_name(String father_name) {
this.father_name = father_name;
}
public String getExam_type() {
return exam_type;
}
public void setExam_type(String exam_type) {
this.exam_type = exam_type;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getNcc_group() {
return ncc_group;
}
public void setNcc_group(String ncc_group) {
this.ncc_group = ncc_group;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getDirectorate() {
return directorate;
}
public void setDirectorate(String directorate) {
this.directorate = directorate;
}
public String getRegiment_number() {
return regiment_number;
}
public void setRegiment_number(String regiment_number) {
this.regiment_number = regiment_number;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
}
LoginActivity.java
package com.tsa.nccapp;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.provider.Settings;
import android.text.InputType;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;
import com.tsa.nccapp.Network.NetworkCheck;
import com.tsa.nccapp.custom.CustomActivity;
import com.tsa.nccapp.custom.RightDrawableOnTouchListener;
import com.tsa.nccapp.models.LoginModel;
import com.tsa.nccapp.models.UserModel;
import com.tsa.nccapp.utils.GLOBAL;
import com.tsa.nccapp.validation.Validation;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Hashtable;
import java.util.Map;
/********************************************************
* A login screen that offers login via email/password. *
********************************************************/
public class LoginActivity2 extends CustomActivity {
private static final int RC_SIGN_IN = 1;
private static Context context;
private EditText username;
private EditText password;
private boolean pwdFlag = false;
private GoogleSignInClient mGoogleSignInClient;
SharedPreferences sharedPref;
LinearLayout mainRoot;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login2);
context = LoginActivity2.this;
sharedPref = context.getSharedPreferences(
"login", Context.MODE_PRIVATE);
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
init();
}
/////////////////////////
private void init() {
username = findViewById(R.id.user_name);
password = findViewById(R.id.password);
mainRoot=findViewById(R.id.main_root);
findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (NetworkCheck.checkInternet(mainRoot,context))
signIn();
}
});
password.setOnTouchListener(new RightDrawableOnTouchListener(password) {
@Override
public boolean onDrawableTouch(final MotionEvent event) {
return onClickSearch(event);
}
});
}
//////////////////////////////////////////
public void goToDashboard(View view) {
if (checkValidation()) {
if (NetworkCheck.checkInternet(mainRoot,context)) {
login(username.getText().toString(), password.getText().toString());
}
}
}
///////////////////////////////////////////
public void goRegistration(View view) {
if (NetworkCheck.checkInternet(mainRoot,context)) {
startActivity(new Intent(LoginActivity2.this, Signup_oneActivity.class));
finish();
}
}
////////////////////////////////////////////////////////////////
public void login(final String username, final String password) {
//Showing the progress dialog
final ProgressDialog progress = new ProgressDialog(LoginActivity2.this);
progress.show();
StringRequest stringRequest = new StringRequest(Request.Method.POST, GLOBAL.baseURL+ "loginUser.php",
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
Log.d("Login", s.toString());
try {
JSONObject json = new JSONObject(s);
if (json.getString("status").equals("0")) {
GLOBAL.globalLoginModel = new LoginModel();
// GLOBAL.globalLoginModel.setName_of_cadet(json.getString("name_of_cadet"));
GLOBAL.globalLoginModel.setEmail(json.getString("email"));
GLOBAL.globalLoginModel.setMobile(json.getString("mobile"));
GLOBAL.globalLoginModel.setRegiment_number(json.getString("regiment_number"));
GLOBAL.globalLoginModel.setRank(json.getString("rank"));
GLOBAL.globalLoginModel.setFather_name(json.getString("father_name"));
GLOBAL.globalLoginModel.setExam_type(json.getString("exam_type"));
GLOBAL.globalLoginModel.setUnit(json.getString("unit"));
GLOBAL.globalLoginModel.setNcc_group(json.getString("ncc_group"));
GLOBAL.globalLoginModel.setState(json.getString("state"));
GLOBAL.globalLoginModel.setDistrict(json.getString("district"));
GLOBAL.globalLoginModel.setTown(json.getString("town"));
GLOBAL.globalLoginModel.setDirectorate(json.getString("directorate"));
GLOBAL.globalLoginModel.setUsername(json.getString("username"));
GLOBAL.globalLoginModel.setPassword(json.getString("password"));
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
GLOBAL.loginType=GLOBAL.USERLOGIN;
Log.d("Login", s.toString());
startActivity(new Intent(LoginActivity2.this, Main2Activity.class));
finish();
} else {
Log.d("Login", s.toString());
progress.dismiss();
Toast.makeText(context, "Invalid User Name or Password", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
progress.dismiss();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(context, "Some issue in loading" + volleyError, Toast.LENGTH_LONG).show();
progress.dismiss();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new Hashtable<String, String>();
params.put("username", username);
params.put("password", password);
params.put("status", "Login");
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(LoginActivity2.this);
requestQueue.add(stringRequest);
}
////////////////////////////////////////////////////////////
private boolean onClickSearch(final MotionEvent event) {
// do something
pwdFlag = !pwdFlag;
if (pwdFlag) {
password.setInputType(InputType.TYPE_CLASS_TEXT);
password.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.off_eye, 0);
} else {
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
password.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.eye_20, 0);
}
event.setAction(MotionEvent.ACTION_CANCEL);
return false;
}
///////////////////////////////////////
private boolean checkValidation() {
boolean ret = true;
if (!Validation.hasText(password)) ret = false;
if (!Validation.hasText(username)) ret = false;
return ret;
}
///////////////////////////////////
public void goHome(View view) {
if(NetworkCheck.checkInternet(mainRoot,context)) {
GLOBAL.globalLoginModel = new LoginModel();
Log.e("json", GLOBAL.globalLoginModel.toString());
GLOBAL.globalLoginModel.setName_of_cadet("Guest User");
GLOBAL.globalLoginModel.setUsername("Guest User");
/*GLOBAL.loginType=GLOBAL.GUESTLOGIN;*/
startActivity(new Intent(LoginActivity2.this, Main2Activity.class));
finish();
}
}
///////////////////////////////
// @Override
// protected void onStart() {
// super.onStart();
// if (NetworkCheck.checkInternet(mainRoot,context)) {
// GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
// if (account != null) {
// GLOBAL.globalLoginModel = new LoginModel();
// GLOBAL.globalLoginModel.setUsername(account.getDisplayName());
// GLOBAL.globalLoginModel.setName_of_cadet(account.getDisplayName());
// GLOBAL.globalLoginModel.setEmail(account.getEmail());
// GLOBAL.photoURL = "" + account.getPhotoUrl();
// /* GLOBAL.loginType=GLOBAL.GMAILLOGIN;*/
// startActivity(new Intent(LoginActivity2.this, Main2Activity.class));
// finish();
// }
// }
// }
///////////////////////////
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
/////////////////////////////////////////////////////////////////////////////////
// @Override
// public void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
// if (requestCode == RC_SIGN_IN) {
// Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
// handleSignInResult(task);
// }
// }
////////////////////////////////////////////////////////////////////////////////
// private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
// try {
// GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// GLOBAL.globalLoginModel = new LoginModel();
// GLOBAL.globalLoginModel.setUsername(account.getDisplayName());
// GLOBAL.globalLoginModel.setName_of_cadet(account.getDisplayName());
// GLOBAL.globalLoginModel.setEmail(account.getEmail());
// GLOBAL.photoURL = "" + account.getPhotoUrl();
// registerWithGPlus();
// } catch (ApiException e) {
// Log.w("TAG", "signInResult:failed code=" + e.getStatusCode());
// }
//}
////////////////////////////////////////////////////////////////////////////////////////////////
public void goFargotPwd(View view) {
if (NetworkCheck.checkInternet(mainRoot,context)){
startActivity(new Intent(context, ForgetPasswordActivity.class));
finish();}
}
////////////////////////////////////////////////////////////////////////////////////////////////
// public void registerWithGPlus() {
// //Showing the progress dialog
// final ProgressDialog progress = new ProgressDialog(context);
// progress.show();
// StringRequest stringRequest = new StringRequest(Request.Method.POST, GLOBAL.baseURL + "social_media_login.php",
// new Response.Listener<String>() {
// @Override
// public void onResponse(String s) {
// try {
// JSONObject json = new JSONObject(s);
// Log.e("j son", json.toString());
// progress.dismiss();
// /* GLOBAL.loginType=GLOBAL.GMAILLOGIN;*/
// startActivity(new Intent(LoginActivity2.this, Main2Activity.class));
// finish();
// } catch (JSONException e) {
// e.printStackTrace();
// progress.dismiss();
// }
// }
//
// },
// new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError volleyError) {
// //Showing toast
// Toast.makeText(context, "Some issue in loading" + volleyError, Toast.LENGTH_LONG).show();
// progress.dismiss();
// }
// }) {
// @Override
// protected Map<String, String> getParams() throws AuthFailureError {
//
// //Creating parameters
// Map<String, String> params = new Hashtable<String, String>();
//
// //Adding parameters
// params.put("email", "" + GLOBAL.globalLoginModel.getEmail());
// params.put("name", "" + GLOBAL.globalLoginModel.getName_of_cadet());
// params.put("mobile", "" + GLOBAL.globalLoginModel.getMobile());
// params.put("state", "" + GLOBAL.globalLoginModel.getState());
// params.put("social_media", "Gmail");
//
// return params;
// }
// };
//Creating a Request Queue
// RequestQueue requestQueue = Volley.newRequestQueue(context);
//
// //Adding request to the queue
// requestQueue.add(stringRequest);
// }
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("Really Exit?")
.setMessage("Are you sure you want to exit?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
LoginActivity2.super.onBackPressed();
}
}).create().show();
}
}
Global.java
package com.tsa.nccapp.utils;
import com.tsa.nccapp.R;
import com.tsa.nccapp.models.CadetDetailsModels;
import com.tsa.nccapp.models.LoginModel;
import com.tsa.nccapp.models.OtherExamResultModel;
import com.tsa.nccapp.models.PasswordModel;
import com.tsa.nccapp.models.ReportModel;
import com.tsa.nccapp.models.UserModel;
import java.util.ArrayList;
import java.util.Stack;
/**
* Created by Akhil Tripathi on 28-12-2017.
*/
public class GLOBAL {
public final static String baseURL="http://internationalskills.co.in/nccdarpan/API/";
public static UserModel globalUserModel=null;
public static LoginModel globalLoginModel=null;
public static PasswordModel globalPasswordModel=null;
public static String url="";
public static String cert="A";
public static int xD=0;
public static int yD=0;
public static final int GMAILLOGIN=2;
public static final int GUESTLOGIN=1;
public static final int USERLOGIN=0;
public static int loginType=USERLOGIN;
public static String password;
public static String username;
public static int textColor= R.color.black;
public static int BGColor= R.color.light_green;
public static int textSize= 14;
public static int scrollAmount=0;
public static ArrayList<ReportModel> reportModels;
public static Stack<Integer> lastVisitedIndex=new Stack<>();
public static String photoURL="https://icons8.com/A.png";
public static ArrayList<OtherExamResultModel> otherExamResultModels=new ArrayList<>();
public static CadetDetailsModels cadetFormModel;
}