- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试启动 Activity checkin1。我正在使用 volley 并从 mySQL db 请求信息以显示在四个编辑文本字段中。
我正在使用我在我的应用程序的其他 Activity ( session 管理器)中使用的相同策略,并且我的代码是相同的,因为我一直在交叉引用并想知道为什么第 47 行会发生错误:
checkin1 第 47 行 HashMap<String, String> user= sessionManager.GetCheckInInfo();getId = user.get(sessionManager.ID);
我相信这可能是我的 session 管理器中的问题( SessionManager 的第 130 行 - GetCheckInInfo();),但我不确定,因为它与我一直在交叉引用和工作的其他类几乎相同美好的。任何帮助,将不胜感激!
session 管理器.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();
}```
最佳答案
NullPointerException is thrown when program attempts to use an objectreference that has the null value.
sessionManager = new SessionManager(checkin1.this);
HashMap<String, String> user= sessionManager.GetCheckInInfo();
getId = user.get(sessionManager.ID);
关于java - 由于 NullPointerException : Attempt to invoke virtual method HashMap on a null object reference 无法启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62898202/
我有不同的结构,它们都包含一个 HashMap与 String作为键,但具有不同的值类型。例如,一个结构有一个类型为 HashMap 的成员, 另一个将有一个 HashMap 类型的成员, 等等。 我
我想制作一个包含学生姓名和科目的板,每个学生在每个科目中都有一个成绩(或者没有..他可以离开考试而不写,然后他的案子将是空的)。我只想使用 HashMap。我的意思是,它会是这样的: HashMap>
是否有内存和速度高效的方法来在 HashMap 中动态存储唯一键:值对? key 保证是唯一的,但它们的数量经常变化。插入和删除必须很快。 我所做的是包含有符号距离场的八叉树(非线性/完整)。八叉树经
有谁知道为什么选择通过 LinkedList 而不是另一个 Hashmap 来实现 HashMap 的存储桶。如果桶本身变成了 HashMap,那么 contains 或 get 的时间复杂度似乎是
我想创建一个具有嵌套结构的 HashMap,就像这个复杂的示例: { type: boy name: Phineas father: type: man
这个问题在这里已经有了答案: How do I create a global, mutable singleton? (7 个答案) 关闭 7 年前。 我想要一个可扩展的字典,将 Object 与
HashMap> hm = new HashMap>(); hm.put("Title1","Key1"); for(int i=0;i hm1 = new H
我必须修改当前代码以适应 Spring MVC。我有 HashMap hashmap = new HashMap(); request.setAttribute("dslrErrors", hashm
我正在尝试进行一些错误捕获。 错误应该检查数组的长度是否小于 2,并检查 HashMap 是否包含用户输入的键。 捕获的错误必须仅使用 if 语句,并且必须使用 .length() 方法,并且必须使用
在 stackoverflow 上提出另一个问题后,(Java- Why this program not throwing concurrent Modification exception)我开始
我有两个类,想使用 org.dozer.Mapper( http://dozer.sourceforge.net/ ) 将 Female 对象的属性映射到 Male 对象。 第一类是: public
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
是否有任何方法可以检查 HashMap 是否包含一组特定的键(这些键是在数组中给出的)。当我尝试类似下面的代码时,它返回 false。 map.containsKey(arrayOf("2018-01
跟进我的问题:How To Access hash maps key when the key is an object 我想尝试这样的事情:webSearchHash.put(xfile.getPa
我有一个可扩展的 ListView ,对于每个 child ,我需要有 4 个“额外”或字符串或其他名称来调用它:- 子标题- 描述- 链接1- 链接2 跟着教程,创建 ListView 、不同的 p
我想确保这是正确的,因为如果不正确,它可能会破坏我的应用程序。 我有这个: private static HashMap> balance = new HashMap<>(); 如果我得到这样的值:
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我是一名优秀的程序员,十分优秀!