我认为按钮点击监听器或验证码存在问题,但不知道此错误的来源。
以下是我的 java文件代码:
public class SignUp extends AppCompatActivity {
private static final String TAG = "SignUp";
private Vibrator vib;
Animation animShake;
private EditText signupInputName, signupInputEmail, signupInputPassword, signupInputDOB;
private TextInputLayout signupInputLayoutName, signupInputLayoutEmail, signupInputLayoutPasword, signupInputLayoutDOB;
private Button btnSignUp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_up_form);
signupInputLayoutName = (TextInputLayout) findViewById(R.id.sign_up_name);
signupInputLayoutName = (TextInputLayout) findViewById(R.id.sign_up_email);
signupInputLayoutName = (TextInputLayout) findViewById(R.id.sign_up_Password);
signupInputLayoutName = (TextInputLayout) findViewById(R.id.sign_up_DOB);
signupInputName = (EditText) findViewById(R.id.signup_input_name);
signupInputName = (EditText) findViewById(R.id.signup_input_email);
signupInputName = (EditText) findViewById(R.id.signup_input_Password);
signupInputName = (EditText) findViewById(R.id.signup_input_DOB);
btnSignUp = (Button) findViewById(R.id.btn_signUp);
animShake = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.shake);
vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
register();
}
});
}
public void register() {
submitForm();
{
if (!checkName() || !checkEmail() || !checkDOB() || !checkPassword()) {
Toast.makeText(this, "signup failed", Toast.LENGTH_SHORT).show();
} else {
onSignupSuccess();
}
}
}
public void onSignupSuccess() {
Intent intent = new Intent(SignUp.this, tab1Petrol.class);
startActivity(intent);
finish();
}
private void submitForm() {
if (!checkName()) {
signupInputName.setAnimation(animShake);
signupInputName.startAnimation(animShake);
vib.vibrate(125);
return;
}
if (!checkEmail()) {
signupInputEmail.setAnimation(animShake);
signupInputEmail.startAnimation(animShake);
vib.vibrate(125);
return;
}
if (!checkPassword()) {
signupInputPassword.setAnimation(animShake);
signupInputPassword.startAnimation(animShake);
vib.vibrate(125);
return;
}
if (!checkDOB()) {
signupInputDOB.setAnimation(animShake);
signupInputDOB.startAnimation(animShake);
vib.vibrate(125);
return;
}
signupInputLayoutName.setErrorEnabled(false);
signupInputLayoutEmail.setErrorEnabled(false);
signupInputLayoutPasword.setErrorEnabled(false);
signupInputLayoutDOB.setErrorEnabled(false);
Toast.makeText(this, "you are successfully Registered", Toast.LENGTH_SHORT).show();
}
private boolean checkName() {
if (signupInputName.getText().toString().trim().isEmpty()) {
signupInputLayoutName.setErrorEnabled(true);
signupInputLayoutName.setError("Please enter a Name");
signupInputName.setError("valid Input Required");
return false;
}
signupInputLayoutName.setErrorEnabled(false);
return true;
}
private boolean checkEmail() {
String email = signupInputEmail.getText().toString().trim();
if (email.isEmpty() || !isValidEmail(email)) {
signupInputLayoutEmail.setErrorEnabled(true);
signupInputLayoutEmail.setError("Please enter a Valid Email");
signupInputEmail.setError("valid Input Required");
requestFocus(signupInputEmail);
return false;
}
signupInputLayoutEmail.setErrorEnabled(false);
return true;
}
private boolean checkPassword() {
if (signupInputPassword.getText().toString().trim().isEmpty()) {
signupInputLayoutPasword.setError("Please enter password");
requestFocus(signupInputPassword);
return false;
}
signupInputLayoutPasword.setErrorEnabled(false);
return true;
}
private boolean checkDOB() {
try {
boolean isDateValid = false;
String[] s = signupInputDOB.getText().toString().split("/");
int date = Integer.parseInt(s[0]);
int month = Integer.parseInt(s[1]);
if (date < 32 && month < 13)
isDateValid = true;
if (signupInputDOB.getText().toString().trim().isEmpty() && isDateValid) {
signupInputLayoutDOB.setError("Enter a valid D.O.B");
requestFocus(signupInputDOB);
signupInputDOB.setError("valid input required");
return false;
}
} catch (Exception ex) {
signupInputLayoutDOB.setError("Enter a valid D.O.B");
requestFocus(signupInputDOB);
return false;
}
signupInputDOB.setError(null);
return true;
}
private static boolean isValidEmail(String email) {
return !TextUtils.isEmpty(email) && Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
private void requestFocus(View view) {
if (view.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
}
XML文件代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center">
<android.support.design.widget.TextInputLayout
android:id="@+id/sign_up_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<EditText
android:id="@+id/signup_input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/sign_up_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<EditText
android:id="@+id/signup_input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="Email" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/sign_up_Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<EditText
android:id="@+id/signup_input_Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:hint="Password" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/sign_up_DOB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<EditText
android:id="@+id/signup_input_DOB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:maxLines="1"
android:hint="Date of Birth" />
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/gender_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am"
android:fontFeatureSettings="Password"
android:textSize="20dp"
android:fontFamily="Password"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/gender_textView"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:checked="true"/>
<RadioButton
android:id="@+id/Female_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"/>
</RadioGroup>
</RelativeLayout>
<Button
android:id="@+id/btn_signUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:text="Sign Up"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
对于初学者来说,你在这里重新分配输入字段,覆盖前一个...我很确定问题是因为这个。
signupInputName = (EditText) findViewById(R.id.signup_input_name);
signupInputName = (EditText) findViewById(R.id.signup_input_email);
signupInputName = (EditText) findViewById(R.id.signup_input_Password);
signupInputName = (EditText) findViewById(R.id.signup_input_DOB);
signupInputLayoutName = (TextInputLayout) findViewById(R.id.sign_up_name);
signupInputLayoutName = (TextInputLayout) findViewById(R.id.sign_up_email);
signupInputLayoutName = (TextInputLayout) findViewById(R.id.sign_up_DOB);
onCreate()
checkEmail()
后代码执行的第一件事就是R.id.signup_input_email
,而且如上所述,signupInputEmail
没有分配checkEmail()
。
您的代码将抛出异常,因为if (!checkEmail()) { ... }
引用了一个NULL变量。
data have ;
input company &:$20. year exit ;
cards;
company 2 2007 9999
company 2 2008 9999
company 2 2009 2009
company 3 2007 9999
company 3 2008 9999
company 3 2009 9999
company 3 2010 9999
company 4 2007 9999
company 4 2008 2008
;
data want ;
merge have
have(keep=company exit rename=(exit=final)
where=(final ne 9999) )
;
by company ;
exit = coalesce(final,exit);
run;