Я пытаюсь начать проверку активности1. Я использую залп и запрашиваю информацию из mySQL db для отображения в четырех текстовых полях редактирования.
Я использую ту же стратегию, которую использовал в других действиях (sessionmanager) моего приложения, и мой код идентичен Я продолжаю выполнять перекрестные ссылки и задаюсь вопросом, почему ошибка возникает в строке 47:
строка 47 checkin1 HashMap<String, String> user= sessionManager.GetCheckInInfo();getId = user.get(sessionManager.ID);
Я считаю, что это может быть проблема в моем диспетчере сеансов ( line130 из SessionManager - GetCheckInInfo ();), но я не уверен, потому что он практически идентичен другим моим классам, которые я использовал для перекрестных ссылок, и работает нормально. Любая помощь будет принята с благодарностью!
Sessionmanager. java
public class SessionManager {
SharedPreferences sharedPreferences;
public SharedPreferences.Editor editor;
public Context context;
int Private_Mode = 0;
private static final String PREF_NAME= "LOGIN";
private static final String LOGIN = "IS_LOGIN";
public static final String USERNAME= "USERNAME";
public static final String EMAIL= "EMAIL";
public static final String ID = "ID";
public static final String PHONE = "PHONE_NUMBER";
private static final String ADDSM= "ADDITIONAL_SOCIAL_MEDIA";
private static final String HCNAME = "HOME_COUNTRY_EMERGENCY_CONTACT_NAME";
public static final String HCPHONE = "HOME_COUNTRY_EMERGENCY_PHONE_NUMBER";
public static final String HCEMAIL= "HOME_COUNTRY_EMERGENCY_CONTACT_EMAIL";
public static final String USANAME = "USA_EMERGENCY_CONTACT_NAME";
public static final String USAPHONE= "USA_EMERGENCY_PHONE_NUMBER";
public static final String USAEMAIL= "USA_EMERGENCY_CONTACT_EMAIL";
public static final String WHATSAPP = "WHATSAPP";
public static final String ADDRESS= "ADDRESS";
public static final String START_DATE= "START_DATE";
public static final String END_DATE= "END_DATE";
public SessionManager(Context context){
this.context = context;
sharedPreferences = context.getSharedPreferences(PREF_NAME, Private_Mode);
editor = sharedPreferences.edit();
}
public void createSession(String username, String email, String id){
editor.putBoolean(LOGIN, true);
editor.putString(USERNAME, username);
editor.putString(EMAIL, email);
editor.putString(ID, id);
editor.apply();
}
public boolean isLoggin(){
return sharedPreferences.getBoolean(LOGIN, false);
}
public void checkLogin(){
if (!this.isLoggin()){
Intent i = new Intent(context, Register.class);
context.startActivity(i);
((MainActivity)context).finish();
}
}
public HashMap<String, String> getUserDetail(){
HashMap<String, String> user = new HashMap<>();
user.put(USERNAME, sharedPreferences.getString(USERNAME, null));
user.put(EMAIL, sharedPreferences.getString(EMAIL, null));
user.put(ID, sharedPreferences.getString(ID, null));
return user;
}
public void logout(){
editor.clear();
editor.commit();
Intent i = new Intent(context, LoginActivity.class);
context.startActivity(i);
((MainActivity)context).finish();
}
public void createSession2(String username, String id, String phone_number, String additional_social_media,
String home_country_emergency_contact_name, String address,
String home_country_emergency_phone_number, String home_country_emergency_contact_email,
String usa_emergency_contact_name, String usa_emergency_phone_number,
String usa_emergency_contact_email, String whatsapp){
editor.putBoolean(LOGIN, true);
editor.putString(USERNAME, username);
editor.putString(ID, id);
editor.putString(PHONE, phone_number);
editor.putString(ADDRESS, address);
editor.putString(HCPHONE, home_country_emergency_phone_number);
editor.putString(HCNAME, home_country_emergency_contact_name);
editor.putString(HCEMAIL, home_country_emergency_contact_email);
editor.putString(USAPHONE, usa_emergency_phone_number);
editor.putString(USANAME, usa_emergency_contact_name);
editor.putString(USAEMAIL, usa_emergency_contact_email);
editor.putString(WHATSAPP, whatsapp);
editor.putString(ADDSM, additional_social_media);
editor.apply();
}
public void createSessionMCI(String username, String id, String phone_number, String email, String address){
editor.putBoolean(LOGIN, true);
editor.putString(USERNAME, username);
editor.putString(ID, id);
editor.putString(PHONE, phone_number);
editor.putString(ADDRESS, address);
editor.putString(EMAIL, email);
editor.apply();
}
public HashMap<String, String> getUserDetail2(){
HashMap<String, String> user = new HashMap<>();
user.put(USERNAME, sharedPreferences.getString(USERNAME, null));
user.put(ID, sharedPreferences.getString(ID, null));
user.put(ADDRESS, sharedPreferences.getString(ADDRESS, null));
user.put(WHATSAPP, sharedPreferences.getString(WHATSAPP, null));
user.put(PHONE, sharedPreferences.getString(PHONE, null));
user.put(ADDSM, sharedPreferences.getString(ADDSM, null));
user.put(HCNAME, sharedPreferences.getString(HCNAME, null));
user.put(HCPHONE, sharedPreferences.getString(HCPHONE, null));
user.put(HCEMAIL, sharedPreferences.getString(HCEMAIL, null));
user.put(USANAME, sharedPreferences.getString(USANAME, null));
user.put(USAPHONE, sharedPreferences.getString(USAPHONE, null));
user.put(USAEMAIL, sharedPreferences.getString(USAEMAIL, null));
return user;
}
public HashMap<String, String> getUserDates() {
HashMap<String, String> user = new HashMap<>();
user.put(START_DATE, sharedPreferences.getString(START_DATE, null));
user.put(END_DATE, sharedPreferences.getString(END_DATE, null));
user.put(ID, sharedPreferences.getString(ID, null));
return user;
}
public HashMap<String, String> GetCheckInInfo() {
HashMap<String, String> user = new HashMap<>();
user.put(USERNAME, sharedPreferences.getString(USERNAME, null));
user.put(EMAIL, sharedPreferences.getString(EMAIL, null));
user.put(PHONE, sharedPreferences.getString(PHONE, null));
user.put(ADDRESS, sharedPreferences.getString(ADDRESS, null));
user.put(ID, sharedPreferences.getString(ID, null));
return user;
}
}
checkin1. java
private static final String TAG = checkin1.class.getSimpleName();
EditText phone_number, address, email, username;
SessionManager sessionManager;
private static String URL_ReadCheckin= "http://192.168.0.86:80/ReadCheckIns.php";
private static String URL_EDITCheckIN = "http://192.168.0.86:80/edit_detailcheckin.php";
String getId;
Button GoToJournal, GoToMain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checkin1);
HashMap<String, String> user= sessionManager.GetCheckInInfo();
getId = user.get(sessionManager.ID);
phone_number = findViewById(R.id.updatePhone);
email = findViewById(R.id.updateEmail);
address = findViewById(R.id.updateAddress);
username = findViewById(R.id.updateUsername);
GoToJournal = findViewById(R.id.myjournalbtn);
GoToMain = findViewById(R.id.mainmenubtn);
GoToMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(checkin1.this, MainActivity.class));
SaveEditDetail();
}
});
GoToJournal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(checkin1.this, myJournal.class));
SaveEditDetail();
}
});
}
// get info
private void getCheckInDetails(){
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.show();
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_ReadCheckin,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
Log.i(TAG, response.toString());
try {
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
JSONArray jsonArray = jsonObject.getJSONArray("read");
if(success.equals("1")){
for (int i =0; i < jsonArray.length(); i++){
JSONObject object= jsonArray.getJSONObject(i);
String strUserName = object.getString("username").trim();
String strEmail = object.getString("email").trim();
String strAddress = object.getString("address").trim();
String strPhone = object.getString("phone_number").trim();
phone_number.setText(strPhone);
address.setText(strAddress);
username.setText(strUserName);
email.setText(strEmail);
}
}
} catch (JSONException e) {
e.printStackTrace();
progressDialog.dismiss();
Toast.makeText(checkin1.this, "Error Reading Details " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(checkin1.this, "Error Reading Details " + error.toString(), Toast.LENGTH_SHORT).show();
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("id", getId);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
@Override
protected void onResume(){
super.onResume();
getCheckInDetails();
}```