Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在login.class上验证时,来自SharedReferences的数据不正确 Login.class 注册类 导入android.content.Intent; 导入android.content.SharedReferences; 导入android.preference.PreferenceManager; 导入android.support.v7.app.AppActivity; 导入android.os.Bundle; 导入android.util.Patterns; 导入android.view.view; 导入android.widget.Button; 导入android.widget.EditText; 导入android.widget.TextView; 导入android.widget.Toast; 导入java.util.regex.Pattern; 公共类注册扩展了应用程序活动{ 编辑文本Lname、Fname、MNName、BDate、电子邮件、密码; 字符串lname、fname、mname、Bdatee、电子邮件、密码; 文本视图登录; 按钮注册,取消; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u注册); Lname=(EditText)findViewById(R.id.txtFamilyName); Fname=(EditText)findViewById(R.id.txtFirstName); Mname=(EditText)findViewById(R.id.txtMiddleName); BDate=(EditText)findViewById(R.id.txtBDay); Email=(EditText)findviewbyd(R.id.txtEMail); 密码=(EditText)findViewById(R.id.txtPassword); 寄存器=(按钮)findViewById(R.id.btnRegister); 取消=(按钮)findViewById(R.id.btnCancel); Login=(TextView)findviewbyd(R.id.txtLogin); Login.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ 意图=新意图(Registration.this、Login.class); 星触觉(意向); } }); Cancel.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ Lname.setText(“”); Fname.setText(“”); Mname.setText(“”); b日期。setText(“”); Email.setText(“”); Password.setText(“”); } }); Register.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ 寄存器(); } }); } 公开作废登记册(){ 初始化(); 如果(!validate()){ Toast.makeText(此“注册失败”,Toast.LENGTH_SHORT.show(); }否则{ onSignUpSuccess(); } } public void onSignUpSuccess(){ save(); Toast.makeText(这是“成功注册!”,Toast.LENGTH_SHORT.show(); 意图=新意图(Registration.this、Login.class); 星触觉(意向); } 公共布尔验证(){ 布尔有效=真; if(lname.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(lname.matches()){ setError(“仅输入字母!”); 有效=错误; } if(Mnamee.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(Mnamee.matches()){ Mname.setError(“仅输入字母!”); 有效=错误; } if(Fnamee.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(Fnamee.matches()){ setError(“仅输入字母!”); 有效=错误; } if(Emails.isEmpty()| | Pattern.compile(“[a-zA-Z0-9]”+“\\@”+“[a-zA-Z]”+“+”\.“+”[a-zA-Z]”).matcher(Emails.matches()){ setError(“输入有效的电子邮件地址!”); 有效=错误; } if(Passwords.isEmpty()| | Passwords.length()_Java_Android_Validation_Login_Android Sharedpreferences - Fatal编程技术网

在login.class上验证时,来自SharedReferences的数据不正确 Login.class 注册类 导入android.content.Intent; 导入android.content.SharedReferences; 导入android.preference.PreferenceManager; 导入android.support.v7.app.AppActivity; 导入android.os.Bundle; 导入android.util.Patterns; 导入android.view.view; 导入android.widget.Button; 导入android.widget.EditText; 导入android.widget.TextView; 导入android.widget.Toast; 导入java.util.regex.Pattern; 公共类注册扩展了应用程序活动{ 编辑文本Lname、Fname、MNName、BDate、电子邮件、密码; 字符串lname、fname、mname、Bdatee、电子邮件、密码; 文本视图登录; 按钮注册,取消; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u注册); Lname=(EditText)findViewById(R.id.txtFamilyName); Fname=(EditText)findViewById(R.id.txtFirstName); Mname=(EditText)findViewById(R.id.txtMiddleName); BDate=(EditText)findViewById(R.id.txtBDay); Email=(EditText)findviewbyd(R.id.txtEMail); 密码=(EditText)findViewById(R.id.txtPassword); 寄存器=(按钮)findViewById(R.id.btnRegister); 取消=(按钮)findViewById(R.id.btnCancel); Login=(TextView)findviewbyd(R.id.txtLogin); Login.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ 意图=新意图(Registration.this、Login.class); 星触觉(意向); } }); Cancel.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ Lname.setText(“”); Fname.setText(“”); Mname.setText(“”); b日期。setText(“”); Email.setText(“”); Password.setText(“”); } }); Register.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ 寄存器(); } }); } 公开作废登记册(){ 初始化(); 如果(!validate()){ Toast.makeText(此“注册失败”,Toast.LENGTH_SHORT.show(); }否则{ onSignUpSuccess(); } } public void onSignUpSuccess(){ save(); Toast.makeText(这是“成功注册!”,Toast.LENGTH_SHORT.show(); 意图=新意图(Registration.this、Login.class); 星触觉(意向); } 公共布尔验证(){ 布尔有效=真; if(lname.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(lname.matches()){ setError(“仅输入字母!”); 有效=错误; } if(Mnamee.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(Mnamee.matches()){ Mname.setError(“仅输入字母!”); 有效=错误; } if(Fnamee.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(Fnamee.matches()){ setError(“仅输入字母!”); 有效=错误; } if(Emails.isEmpty()| | Pattern.compile(“[a-zA-Z0-9]”+“\\@”+“[a-zA-Z]”+“+”\.“+”[a-zA-Z]”).matcher(Emails.matches()){ setError(“输入有效的电子邮件地址!”); 有效=错误; } if(Passwords.isEmpty()| | Passwords.length()

在login.class上验证时,来自SharedReferences的数据不正确 Login.class 注册类 导入android.content.Intent; 导入android.content.SharedReferences; 导入android.preference.PreferenceManager; 导入android.support.v7.app.AppActivity; 导入android.os.Bundle; 导入android.util.Patterns; 导入android.view.view; 导入android.widget.Button; 导入android.widget.EditText; 导入android.widget.TextView; 导入android.widget.Toast; 导入java.util.regex.Pattern; 公共类注册扩展了应用程序活动{ 编辑文本Lname、Fname、MNName、BDate、电子邮件、密码; 字符串lname、fname、mname、Bdatee、电子邮件、密码; 文本视图登录; 按钮注册,取消; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u注册); Lname=(EditText)findViewById(R.id.txtFamilyName); Fname=(EditText)findViewById(R.id.txtFirstName); Mname=(EditText)findViewById(R.id.txtMiddleName); BDate=(EditText)findViewById(R.id.txtBDay); Email=(EditText)findviewbyd(R.id.txtEMail); 密码=(EditText)findViewById(R.id.txtPassword); 寄存器=(按钮)findViewById(R.id.btnRegister); 取消=(按钮)findViewById(R.id.btnCancel); Login=(TextView)findviewbyd(R.id.txtLogin); Login.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ 意图=新意图(Registration.this、Login.class); 星触觉(意向); } }); Cancel.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ Lname.setText(“”); Fname.setText(“”); Mname.setText(“”); b日期。setText(“”); Email.setText(“”); Password.setText(“”); } }); Register.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图){ 寄存器(); } }); } 公开作废登记册(){ 初始化(); 如果(!validate()){ Toast.makeText(此“注册失败”,Toast.LENGTH_SHORT.show(); }否则{ onSignUpSuccess(); } } public void onSignUpSuccess(){ save(); Toast.makeText(这是“成功注册!”,Toast.LENGTH_SHORT.show(); 意图=新意图(Registration.this、Login.class); 星触觉(意向); } 公共布尔验证(){ 布尔有效=真; if(lname.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(lname.matches()){ setError(“仅输入字母!”); 有效=错误; } if(Mnamee.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(Mnamee.matches()){ Mname.setError(“仅输入字母!”); 有效=错误; } if(Fnamee.isEmpty()| | Pattern.compile(“[a-zA-Z]*+”).matcher(Fnamee.matches()){ setError(“仅输入字母!”); 有效=错误; } if(Emails.isEmpty()| | Pattern.compile(“[a-zA-Z0-9]”+“\\@”+“[a-zA-Z]”+“+”\.“+”[a-zA-Z]”).matcher(Emails.matches()){ setError(“输入有效的电子邮件地址!”); 有效=错误; } if(Passwords.isEmpty()| | Passwords.length(),java,android,validation,login,android-sharedpreferences,Java,Android,Validation,Login,Android Sharedpreferences,从注册开始,程序的预期行为是:当用户输入姓氏(txtFamilyName)和密码(txtPassword)时,它将存储在SharedReferences中,并将用作用户登录(login.class)和输入MainPage()时要输入的数据 在注册期间(registration.class),当我输入我的家庭或姓氏和密码,并在Login.class上使用它时,即使所需字段正确,它也不会进入主页。我意识到您正在将EditView对象的值与实际的用户名/密码字符串进行比较。您也不希望将Lname和Pa

从注册开始,程序的预期行为是:当用户输入姓氏(txtFamilyName)和密码(txtPassword)时,它将存储在SharedReferences中,并将用作用户登录(login.class)和输入MainPage()时要输入的数据


在注册期间(registration.class),当我输入我的家庭或姓氏和密码,并在Login.class上使用它时,即使所需字段正确,它也不会进入主页。

我意识到您正在将
EditView
对象的值与实际的用户名/密码字符串进行比较。您也不希望将Lname和Password值用作“默认”值。在这种情况下,如果没有保存用户名/密码,它将始终标识为已登录

下面所做的更改应该足够了

public void load() {
    final SharedPreferences pref= PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    SharedPreferences.Editor editor = pref.edit();

    String value=(pref.getString("Name", ""));
    String value2=(pref.getString("Password", ""));

    if (value.equals(Lname.getText().toString()) & value2.equals(Password.getText().toString())){
        LoginSuccess();
    } else{
        Toast.makeText(this, "Last Name or Password Incorrect or Does not Exist!", Toast.LENGTH_SHORT).show();
    }
}

我突然想到,您正在将
EditView
对象的值与实际的用户名/密码字符串进行比较。您也不希望将Lname和Password值用作“默认”值。在这种情况下,如果没有保存用户名/密码,它将始终标识为已登录

下面所做的更改应该足够了

public void load() {
    final SharedPreferences pref= PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    SharedPreferences.Editor editor = pref.edit();

    String value=(pref.getString("Name", ""));
    String value2=(pref.getString("Password", ""));

    if (value.equals(Lname.getText().toString()) & value2.equals(Password.getText().toString())){
        LoginSuccess();
    } else{
        Toast.makeText(this, "Last Name or Password Incorrect or Does not Exist!", Toast.LENGTH_SHORT).show();
    }
}

您是否收到任何类型的消息-崩溃错误或自制消息(如您的祝酒词)在我输入所需字段后,我的祝酒词会弹出:toast.makeText(此“姓氏或密码不正确或不存在!”,toast.LENGTH_SHORT).show()}您是否收到任何类型的消息-崩溃错误或自制消息(例如
public void load() {
    final SharedPreferences pref= PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    SharedPreferences.Editor editor = pref.edit();

    String value=(pref.getString("Name", ""));
    String value2=(pref.getString("Password", ""));

    if (value.equals(Lname.getText().toString()) & value2.equals(Password.getText().toString())){
        LoginSuccess();
    } else{
        Toast.makeText(this, "Last Name or Password Incorrect or Does not Exist!", Toast.LENGTH_SHORT).show();
    }
}