everything was fine with my application, this morning when I try to run it and press on the "Register" button the application crashes.Same goes for another button in the code.Inside the IDE (Android Studio) where it says
btnRegister.setOnClickListener(new View.OnClickListener()
Not sure what I added or charged but here is my code.Not sure if I should add all the code because its too long.
XML FILE
<Button android:id="@+id/btnRegister" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Register" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.505" app:layout_constraintStart_toStartOf="@+id/guideline3" app:layout_constraintTop_toBottomOf="@+id/cbAgreement" />
and here is my Java code
btnRegister = (Button) findViewById(R.id.btnRegister); btnRegister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { initRegister(); } });private void initRegister(){ Log.d(TAG, "initRegister: Started"); if (validateData()) { if (cbAgreement.isChecked()) { showSnackBar(); }else{ Toast.makeText(this, "You need to agree to the License Agreement", Toast.LENGTH_SHORT).show(); } } }private void showSnackBar(){ Log.d(TAG, "showSnackBar: Started"); txtFullName.setVisibility(View.GONE); txtEmail.setVisibility(View.GONE); txtPassword.setVisibility(View.GONE); edtTxtRePassword.setVisibility(View.GONE); String name = edtTxtFullName.getText().toString(); String email = edtTxtEmail.getText().toString(); String country = countrySpinner.getSelectedItem().toString(); String gender = ""; switch (radioGroupGender.getCheckedRadioButtonId()) { case R.id.rbMale: gender = "Male"; break; case R.id.rbFemale: gender = "Female"; break; case R.id.rbOther: gender = "Other"; break; default: gender = "Unknown"; break; } String snackText ="Name " + name +"\n" +"Email " + email +"\n" +"Gender " + gender +"\n" +"Country " + country +"\n"; Snackbar.make(parent, name +" Registered!", Snackbar.LENGTH_INDEFINITE) .setAction("Dismissed", view -> { txtFullName.setText(""); txtEmail.setText(""); txtPassword.setText(""); txtRePassword.setText(""); }).show(); }
Logcat
2021-06-17 18:27:06.107 10598-10598/com.example.registerform D/MainActivity: validateData: Started2021-06-17 18:27:06.107 10598-10598/com.example.registerform E/le.registerfor: Invalid ID 0x00000000.2021-06-17 18:27:06.107 10598-10598/com.example.registerform D/AndroidRuntime: Shutting down VM2021-06-17 18:27:06.113 10598-10598/com.example.registerform E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.registerform, PID: 10598 android.content.res.Resources$NotFoundException: String resource ID #0x0 at android.content.res.Resources.getText(Resources.java:381) at android.content.res.MiuiResources.getText(MiuiResources.java:97) at android.widget.TextView.setText(TextView.java:6397) at com.example.registerform.MainActivity.validateData(MainActivity.java:118) at com.example.registerform.MainActivity.initRegister(MainActivity.java:57) at com.example.registerform.MainActivity.access$000(MainActivity.java:19) at com.example.registerform.MainActivity$2.onClick(MainActivity.java:49) at android.view.View.performClick(View.java:7183) at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119) at android.view.View.performClickInternal(View.java:7156) at android.view.View.access$3500(View.java:820) at android.view.View$PerformClick.run(View.java:27650) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7561) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)2021-06-17 18:27:06.128 10598-10598/com.example.registerform D/OOMEventManagerFK: checkEventAndDumpForJE: 02021-06-17 18:27:06.164 10598-10598/com.example.registerform I/Process: Sending signal. PID: 10598 SIG: 9
private boolean validateData(){ Log.d(TAG, "validateData: Started"); if(edtTxtFullName.getText().toString().equals("")) { txtFullName.setText(View.VISIBLE); return false; } if(edtTxtEmail.getText().toString().equals("")) { txtEmail.setText(View.VISIBLE); return false; } if(edtTxtPassword.getText().toString().equals("")) { txtPassword.setText(View.VISIBLE); return false; } if(edtTxtRePassword.getText().toString().equals("")) { txtRePassword.setText(View.VISIBLE); return false; } if(!edtTxtPassword.getText().toString().equals(edtTxtRePassword.getText().toString())){ Toast.makeText(this, "Password Doesn't Match.", Toast.LENGTH_SHORT).show(); txtRePassword.setText(View.VISIBLE); return false; } return true; }
private void initViews(){ Log.d(TAG,"Started"); edtTxtFullName = findViewById(R.id.edtTxtFullName); edtTxtEmail = findViewById(R.id.edtTxtEmail); edtTxtPassword = findViewById(R.id.edtTxtPassword); edtTxtRePassword = findViewById(R.id.edtTxtRePassword); btnRegister = (Button) findViewById(R.id.btnRegister); btnImage =(Button) findViewById(R.id.btnImage); txtFullName = findViewById(R.id.txtFullName); txtEmail = findViewById(R.id.txtEmail); txtPassword = findViewById(R.id.txtPassword); txtRePassword = findViewById(R.id.txtRePassword); countrySpinner = findViewById(R.id.countrySpinner); radioGroupGender = findViewById(R.id.radioGroupGender); cbAgreement = findViewById(R.id.cbAgreement); parent = findViewById(R.id.parent); }