我正在使用AwesomeValidation库进行验证,应用程序崩溃并且给出一个空对象引用错误,我无法找到什么是null帮助。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.admin.auctioner.SignupActivity"
tools:layout_editor_absoluteY="25dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="82dp"
android:layout_height="0dp"
android:layout_marginBottom="14dp"
android:layout_marginTop="29dp"
android:contentDescription="@string/logodesc"
app:layout_constraintBottom_toTopOf="@+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="34dp"
android:fontFamily="monospace"
android:text="@string/app_name"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/textView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginStart="16dp"
android:text="@string/signuptxt"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout3"
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5">
<android.support.design.widget.TextInputEditText
android:id="@+id/s_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout4"
android:layout_width="0dp"
android:layout_height="74dp"
android:layout_marginBottom="9dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout3"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/s_pass1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout5"
android:layout_width="395dp"
android:layout_height="79dp"
android:layout_marginBottom="13dp"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/button4"
app:layout_constraintEnd_toStartOf="@+id/button4"
app:layout_constraintStart_toStartOf="@+id/button4"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout4"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/s_pass2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cpassword"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button4"
android:layout_width="190dp"
android:layout_height="44dp"
android:layout_marginBottom="25dp"
android:layout_marginEnd="16dp"
android:onClick="signup"
android:text="@string/signup"
app:layout_constraintBottom_toTopOf="@+id/textView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout5" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="65dp"
android:onClick="login_link"
android:text="@string/llink"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button4"
app:layout_constraintStart_toStartOf="@+id/button4"
app:layout_constraintTop_toBottomOf="@+id/button4" />
这是活动代码:
公共类SignupActivity扩展了AppCompatActivity {
TextInputEditText email,pass1,pass2;
FirebaseAuth mAuth;
AwesomeValidation mAwesomeValidation;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Registering user");
email = (TextInputEditText) findViewById(R.id.s_email);
pass1 = (TextInputEditText) findViewById(R.id.s_pass1);
pass2 = (TextInputEditText) findViewById(R.id.s_pass2);
mAuth = FirebaseAuth.getInstance();
mAwesomeValidation = new AwesomeValidation(TEXT_INPUT_LAYOUT);
mAwesomeValidation.addValidation(this,R.id.s_email, Patterns.EMAIL_ADDRESS, R.string.emailerr);
String regexPassword = "(?=.*[a-z])(?=.*[A-Z])(?=.*[\\d])(?=.*[~`!@#\\$%\\^&\\*\\(\\)\\-_\\+=\\{\\}\\[\\]\\|\\;:\"<>,./\\?]).{8,}";
mAwesomeValidation.addValidation(this, R.id.s_pass1, regexPassword, R.string.passerr);
mAwesomeValidation.addValidation(this, R.id.s_pass2, R.id.s_pass1, R.string.passerr);
}
public void signup(View view){
email.setError("Enter valid email");
if (mAwesomeValidation.validate()){
String mail = email.getText().toString().trim();
String pass = pass1.getText().toString().trim();
progressDialog.show();
mAuth.createUserWithEmailAndPassword(mail,pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
Toast.makeText(getApplicationContext(),"Registered successfully",Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),LoginActivity.class));
}
else {
Toast.makeText(getApplicationContext(),"Registration Error",Toast.LENGTH_SHORT).show();
}
}
});
progressDialog.dismiss();
}
}
我收到此错误
FATAL EXCEPTION: main
Process: com.example.admin.auctioner, PID: 20721
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.TextInputLayout.setError(java.lang.CharSequence)' on a null object reference
at com.basgeekball.awesomevalidation.validators.TextInputLayoutValidator.halt(SourceFile:30)
at com.basgeekball.awesomevalidation.validators.TextInputLayoutValidator.trigger(SourceFile:23)
at com.basgeekball.awesomevalidation.AwesomeValidation.validate(SourceFile:139)
at com.example.admin.auctioner.SignupActivity.signup(SignupActivity.java:58)
我也尝试过放入OnStart()方法 得到同样的错误?