Firebase自定义用户字段崩溃 – Android Studio

huangapple go评论87阅读模式
英文:

Firebase Custom Userfield crash - Android Studio

问题

以下是已翻译好的代码部分:

  1. public class SignUp extends AppCompatActivity {
  2. //变量
  3. private EditText regName, regNpm, regUsername, regEmail, regPassword, regCoPassword;
  4. private Button regBtn, regToLoginBtn;
  5. ProgressBar signUp_progress;
  6. private DatabaseReference databaseReference;
  7. private FirebaseDatabase firebaseDatabase;
  8. private FirebaseAuth mAuth;
  9. String fullname, username, email, npm, password, co_password;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
  14. setContentView(R.layout.activity_sign_up);
  15. signUp_progress = findViewById(R.id.signUp_progress);
  16. regName = findViewById(R.id.reg_name);
  17. regNpm = findViewById(R.id.reg_npm);
  18. regUsername = findViewById(R.id.reg_username);
  19. regEmail = findViewById(R.id.reg_email);
  20. regPassword = findViewById(R.id.reg_password);
  21. regCoPassword = findViewById(R.id.reg_CoPassword);
  22. regBtn = findViewById(R.id.reg_btn);
  23. regToLoginBtn = findViewById(R.id.reg_login_btn);
  24. mAuth = FirebaseAuth.getInstance();
  25. firebaseDatabase = FirebaseDatabase.getInstance();
  26. databaseReference = firebaseDatabase.getReference("UserData");
  27. regToLoginBtn.setOnClickListener(new View.OnClickListener() {
  28. @Override
  29. public void onClick(View v) {
  30. Intent intent = new Intent(getApplicationContext(), Login.class);
  31. startActivity(intent);
  32. }
  33. });
  34. regBtn.setOnClickListener(new View.OnClickListener() {
  35. @Override
  36. public void onClick(View v) {
  37. if (!validateFullname() | !validateUsername() | !validateEmail() | !validatePassword() | !validateNpm()) {
  38. return;
  39. }
  40. if (regPassword.equals(regCoPassword)) {
  41. signUp_progress.setVisibility(View.VISIBLE);
  42. mAuth.createUserWithEmailAndPassword(email, String.valueOf(regPassword)).addOnCompleteListener
  43. (new OnCompleteListener<AuthResult>() {
  44. @Override
  45. public void onComplete(@NonNull Task<AuthResult> task) {
  46. if (task.isSuccessful()) {
  47. UserData data = new UserData(fullname, username, email, npm);
  48. FirebaseDatabase.getInstance().getReference("UserData")
  49. .child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(data).
  50. addOnCompleteListener(new OnCompleteListener<Void>() {
  51. @Override
  52. public void onComplete(@NonNull Task<Void> task) {
  53. signUp_progress.setVisibility(View.GONE);
  54. Toast.makeText(SignUp.this, "Successful Registered", Toast.LENGTH_SHORT).show();
  55. Intent intent = new Intent(SignUp.this, MenuActivity.class);
  56. startActivity(intent);
  57. finish();
  58. }
  59. });
  60. } else {
  61. signUp_progress.setVisibility(View.GONE);
  62. Toast.makeText(SignUp.this, "Check Email id or Password", Toast.LENGTH_SHORT).show();
  63. }
  64. }
  65. });
  66. } else {
  67. Toast.makeText(SignUp.this, "Password didn't match", Toast.LENGTH_SHORT).show();
  68. }
  69. }
  70. });
  71. }
  72. // 省略其他部分...
  73. }
  1. public class Login extends AppCompatActivity {
  2. Button callSignUp, loginBtn;
  3. ImageView image;
  4. TextView logoText, sloganText;
  5. TextInputLayout username, password;
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
  10. setContentView(R.layout.activity_login);
  11. callSignUp = findViewById(R.id.signup_screen);
  12. image = findViewById(R.id.logo_image);
  13. logoText = findViewById(R.id.logo_text);
  14. sloganText = findViewById(R.id.slogan_text);
  15. username = findViewById(R.id.username);
  16. password = findViewById(R.id.password);
  17. loginBtn = findViewById(R.id.login_btn);
  18. callSignUp.setOnClickListener(new View.OnClickListener() {
  19. @Override
  20. public void onClick(View v) {
  21. Intent intent = new Intent(Login.this,SignUp.class);
  22. Pair[] pairs = new Pair[7];
  23. pairs[0] = new Pair<View,String>(image,"logo_image");
  24. pairs[1] = new Pair<View,String>(logoText,"logo_text");
  25. pairs[2] = new Pair<View,String>(sloganText,"logo_desc");
  26. pairs[3] = new Pair<View,String>(username,"uname_tran");
  27. pairs[4] = new Pair<View,String>(password,"password_tran");
  28. pairs[5] = new Pair<View,String>(loginBtn,"button_tran");
  29. pairs[6] = new Pair<View,String>(callSignUp,"login_signup_tran");
  30. ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Login.this,pairs);
  31. startActivity(intent, options.toBundle());
  32. }
  33. });
  34. }
  35. }

以上是代码的翻译部分,包括SignUp.javaLogin.java中的关键部分。至于出现的错误日志,是因为在SignUp.java中的布局文件中使用了com.google.android.material.textfield.TextInputLayout,但在代码中使用findViewById查找对应的组件时,使用了EditText而不是TextInputLayout。需要修改相关代码以正确处理布局中的组件。

英文:

As the title said. I want to make a custom authentication with username on Register form. All code was good and there is no error. But when I'm trying to run the app, It's force close when After I click the Registration button from the Login page. So this is the list code in SignUp.java

  1. public class SignUp extends AppCompatActivity {
  2. //Variabel
  3. private EditText regName, regNpm, regUsername, regEmail, regPassword, regCoPassword;
  4. private Button regBtn, regToLoginBtn;
  5. ProgressBar signUp_progress;
  6. private DatabaseReference databaseReference;
  7. private FirebaseDatabase firebaseDatabase;
  8. private FirebaseAuth mAuth;
  9. String fullname, username, email, npm, password, co_password;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. //Line dibawah untuk menghilangkan status bar dari screen
  14. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
  15. setContentView(R.layout.activity_sign_up);
  16. //Hooks ke semua elemen xml di activity_sign_up.xml
  17. signUp_progress = findViewById(R.id.signUp_progress);
  18. regName = findViewById(R.id.reg_name);
  19. regNpm = findViewById(R.id.reg_npm);
  20. regUsername = findViewById(R.id.reg_username);
  21. regEmail = findViewById(R.id.reg_email);
  22. regPassword = findViewById(R.id.reg_password);
  23. regCoPassword = findViewById(R.id.reg_CoPassword);
  24. regBtn = findViewById(R.id.reg_btn);
  25. regToLoginBtn = findViewById(R.id.reg_login_btn);
  26. // Get Firebase auth instance
  27. mAuth = FirebaseAuth.getInstance();
  28. firebaseDatabase = FirebaseDatabase.getInstance();
  29. databaseReference = firebaseDatabase.getReference(&quot;UserData&quot;);
  30. regToLoginBtn.setOnClickListener(new View.OnClickListener() {
  31. @Override
  32. public void onClick(View v) {
  33. Intent intent = new Intent(getApplicationContext(), Login.class);
  34. startActivity(intent);
  35. }
  36. });
  37. // handle user SignUp button
  38. regBtn.setOnClickListener(new View.OnClickListener() {
  39. @Override
  40. public void onClick(View v) {
  41. if (!validateFullname() | !validateUsername() | !validateEmail() | !validatePassword() | !validateNpm()) {
  42. return;
  43. }
  44. if (regPassword.equals(regCoPassword)) {
  45. // progressbar VISIBLE
  46. signUp_progress.setVisibility(View.VISIBLE);
  47. mAuth.createUserWithEmailAndPassword(email, String.valueOf(regPassword)).addOnCompleteListener
  48. (new OnCompleteListener&lt;AuthResult&gt;() {
  49. @Override
  50. public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
  51. if (task.isSuccessful()) {
  52. UserData data = new UserData(fullname, username, email, npm);
  53. FirebaseDatabase.getInstance().getReference(&quot;UserData&quot;)
  54. .child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(data).
  55. addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
  56. @Override
  57. public void onComplete(@NonNull Task&lt;Void&gt; task) {
  58. // progressbar GONE
  59. signUp_progress.setVisibility(View.GONE);
  60. Toast.makeText(SignUp.this, &quot;Successful Registered&quot;, Toast.LENGTH_SHORT).show();
  61. Intent intent = new Intent(SignUp.this, MenuActivity.class);
  62. startActivity(intent);
  63. finish();
  64. }
  65. });
  66. } else {
  67. // progressbar GONE
  68. signUp_progress.setVisibility(View.GONE);
  69. Toast.makeText(SignUp.this, &quot;Check Email id or Password&quot;, Toast.LENGTH_SHORT).show();
  70. }
  71. }
  72. });
  73. } else {
  74. Toast.makeText(SignUp.this, &quot;Password didn&#39;t match&quot;, Toast.LENGTH_SHORT).show();
  75. }
  76. }
  77. });
  78. }
  79. private boolean validateFullname() {
  80. fullname = regName.getText().toString().trim();
  81. if (TextUtils.isEmpty(fullname)) {
  82. Toast.makeText(SignUp.this, &quot;Enter Your Full Name&quot;, Toast.LENGTH_SHORT).show();
  83. return false;
  84. } else {
  85. return true;
  86. }
  87. }
  88. private boolean validateUsername() {
  89. username = regUsername.getText().toString().trim();
  90. if (TextUtils.isEmpty(username)) {
  91. Toast.makeText(SignUp.this, &quot;Enter Your User Name&quot;, Toast.LENGTH_SHORT).show();
  92. return false;
  93. } else {
  94. return true;
  95. }
  96. }
  97. private boolean validateNpm() {
  98. npm = regNpm.getText().toString().trim();
  99. if (TextUtils.isEmpty(npm)) {
  100. Toast.makeText(SignUp.this, &quot;Enter Your NPM&quot;, Toast.LENGTH_SHORT).show();
  101. return false;
  102. } else {
  103. return true;
  104. }
  105. }
  106. private boolean validateEmail() {
  107. email = regEmail.getText().toString().trim();
  108. if (TextUtils.isEmpty(email)) {
  109. Toast.makeText(SignUp.this, &quot;Enter Your Email&quot;, Toast.LENGTH_SHORT).show();
  110. return false;
  111. } else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
  112. Toast.makeText(SignUp.this, &quot;Please enter valid Email&quot;, Toast.LENGTH_SHORT).show();
  113. return false;
  114. } else {
  115. return true;
  116. }
  117. }
  118. private boolean validatePassword() {
  119. password = regPassword.getText().toString().trim();
  120. co_password = regCoPassword.getText().toString().toLowerCase();
  121. if (TextUtils.isEmpty(password)) {
  122. Toast.makeText(SignUp.this, &quot;Enter Your Password&quot;, Toast.LENGTH_SHORT).show();
  123. return false;
  124. } else if (TextUtils.isEmpty(co_password)) {
  125. Toast.makeText(SignUp.this, &quot;Enter Your Co-Password&quot;, Toast.LENGTH_SHORT).show();
  126. return false;
  127. } else if (password.length() &lt;= 6) {
  128. Toast.makeText(SignUp.this, &quot;Password is Very Short&quot;, Toast.LENGTH_SHORT).show();
  129. return false;
  130. } else {
  131. return true;
  132. }
  133. }
  134. // if the user already logged in then it will automatically send on Dashboard/MainActivity activity.
  135. @Override
  136. public void onStart() {
  137. super.onStart();
  138. if (FirebaseAuth.getInstance().getCurrentUser() != null) {
  139. Intent intent = new Intent(SignUp.this, MenuActivity.class);
  140. startActivity(intent);
  141. }
  142. }

}

And this is the listing code from Login.java

  1. public class Login extends AppCompatActivity {
  2. //Variabel
  3. Button callSignUp, loginBtn;
  4. ImageView image;
  5. TextView logoText, sloganText;
  6. TextInputLayout username, password;
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. //Line dibawah untuk menghilangkan status bar dari screen
  11. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
  12. setContentView(R.layout.activity_login);
  13. //Hooks
  14. callSignUp = findViewById(R.id.signup_screen);
  15. image = findViewById(R.id.logo_image);
  16. logoText = findViewById(R.id.logo_text);
  17. sloganText = findViewById(R.id.slogan_text);
  18. username = findViewById(R.id.username);
  19. password = findViewById(R.id.password);
  20. loginBtn = findViewById(R.id.login_btn);
  21. callSignUp.setOnClickListener(new View.OnClickListener() {
  22. @Override
  23. public void onClick(View v) {
  24. Intent intent = new Intent(Login.this,SignUp.class);
  25. Pair[] pairs = new Pair[7];
  26. pairs [0] = new Pair&lt;View,String&gt;(image,&quot;logo_image&quot;);
  27. pairs [1] = new Pair&lt;View,String&gt;(logoText,&quot;logo_text&quot;);
  28. pairs [2] = new Pair&lt;View,String&gt;(sloganText,&quot;logo_desc&quot;);
  29. pairs [3] = new Pair&lt;View,String&gt;(username,&quot;uname_tran&quot;);
  30. pairs [4] = new Pair&lt;View,String&gt;(password,&quot;password_tran&quot;);
  31. pairs [5] = new Pair&lt;View,String&gt;(loginBtn,&quot;button_tran&quot;);
  32. pairs [6] = new Pair&lt;View,String&gt;(callSignUp,&quot;login_signup_tran&quot;);
  33. ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Login.this,pairs);
  34. startActivity(intent, options.toBundle());
  35. }
  36. });
  37. }

}

And then there's logcat

  1. 2020-10-13 00:24:08.213 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
  2. 2020-10-13 00:24:08.225 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
  3. 2020-10-13 00:24:08.230 5297-5336/com.hardy.gunadarmastudentapp E/BufferQueueProducer: [unnamed-5297-8] setMaxDequeuedBufferCount: 2 dequeued buffers would exceed the maxBufferCount (2) (maxAcquired 1 async 0 mDequeuedBufferCannotBlock 0)
  4. 2020-10-13 00:24:08.230 5297-5336/com.hardy.gunadarmastudentapp E/Surface: IGraphicBufferProducer::setBufferCount(3) returned Invalid argument
  5. 2020-10-13 00:24:08.231 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
  6. 2020-10-13 00:24:08.240 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
  7. 2020-10-13 00:24:08.244 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
  8. 2020-10-13 00:24:08.251 5297-5297/com.hardy.gunadarmastudentapp W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@5690764
  9. 2020-10-13 00:24:08.257 5297-5333/com.hardy.gunadarmastudentapp V/FA: onActivityCreated
  10. 2020-10-13 00:24:08.259 5297-5339/com.hardy.gunadarmastudentapp V/FA: Recording user engagement, ms: 12594
  11. 2020-10-13 00:24:08.261 5297-5339/com.hardy.gunadarmastudentapp V/FA: Connecting to remote service
  12. 2020-10-13 00:24:08.267 5297-5339/com.hardy.gunadarmastudentapp V/FA: Activity paused, time: 130626
  13. 2020-10-13 00:24:08.288 5297-5297/com.hardy.gunadarmastudentapp I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
  14. 2020-10-13 00:24:08.312 5297-5297/com.hardy.gunadarmastudentapp I/chatty: uid=10134(com.hardy.gunadarmastudentapp) identical 4 lines
  15. 2020-10-13 00:24:08.320 5297-5297/com.hardy.gunadarmastudentapp I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
  16. 2020-10-13 00:24:08.332 5297-5339/com.hardy.gunadarmastudentapp V/FA: Connection attempt already in progress
  17. 2020-10-13 00:24:08.576 5297-5297/com.hardy.gunadarmastudentapp D/AndroidRuntime: Shutting down VM
  18. 2020-10-13 00:24:09.200 5297-5297/com.hardy.gunadarmastudentapp E/AndroidRuntime: FATAL EXCEPTION: main
  19. Process: com.hardy.gunadarmastudentapp, PID: 5297
  20. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hardy.gunadarmastudentapp/com.hardy.gunadarmastudentapp.SignUp}: java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to android.widget.EditText
  21. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
  22. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
  23. at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
  24. at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
  25. at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  26. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
  27. at android.os.Handler.dispatchMessage(Handler.java:107)
  28. at android.os.Looper.loop(Looper.java:214)
  29. at android.app.ActivityThread.main(ActivityThread.java:7356)
  30. at java.lang.reflect.Method.invoke(Native Method)
  31. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
  32. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
  33. Caused by: java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to android.widget.EditText
  34. at com.hardy.gunadarmastudentapp.SignUp.onCreate(SignUp.java:47)
  35. at android.app.Activity.performCreate(Activity.java:7802)
  36. at android.app.Activity.performCreate(Activity.java:7791)
  37. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
  38. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
  39. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)&#160;
  40. at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)&#160;
  41. at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)&#160;
  42. at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)&#160;
  43. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)&#160;
  44. at android.os.Handler.dispatchMessage(Handler.java:107)&#160;
  45. at android.os.Looper.loop(Looper.java:214)&#160;
  46. at android.app.ActivityThread.main(ActivityThread.java:7356)&#160;
  47. at java.lang.reflect.Method.invoke(Native Method)&#160;
  48. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)&#160;
  49. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)&#160;
  50. 2020-10-13 00:24:10.531 5297-5297/com.hardy.gunadarmastudentapp I/Process: Sending signal. PID: 5297 SIG: 9

Then the activity_sign_up.xml

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  3. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  4. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  5. android:layout_width=&quot;match_parent&quot;
  6. android:layout_height=&quot;match_parent&quot;
  7. tools:context=&quot;.SignUp&quot;
  8. android:orientation=&quot;vertical&quot;
  9. android:background=&quot;#8f4dc9&quot;
  10. android:padding=&quot;20dp&quot;&gt;
  11. &lt;ImageView
  12. android:layout_width=&quot;100dp&quot;
  13. android:layout_height=&quot;100dp&quot;
  14. android:transitionName=&quot;logo_image&quot;
  15. android:src=&quot;@drawable/logogundar&quot;/&gt;
  16. &lt;TextView
  17. android:id=&quot;@+id/logo_name&quot;
  18. android:layout_width=&quot;wrap_content&quot;
  19. android:layout_height=&quot;wrap_content&quot;
  20. android:fontFamily=&quot;@font/acme&quot;
  21. android:text=&quot;Menu Register&quot;
  22. android:textSize=&quot;30sp&quot;
  23. android:transitionName=&quot;logo_text&quot;
  24. android:textColor=&quot;#FFF&quot;/&gt;
  25. &lt;TextView
  26. android:id=&quot;@+id/slogan_name&quot;
  27. android:layout_width=&quot;wrap_content&quot;
  28. android:layout_height=&quot;wrap_content&quot;
  29. android:text=&quot;Isi NPM, username, dan email untuk sign in&quot;
  30. android:textColor=&quot;#FFF&quot;
  31. android:textSize=&quot;15sp&quot;/&gt;
  32. &lt;LinearLayout
  33. android:layout_width=&quot;match_parent&quot;
  34. android:layout_height=&quot;wrap_content&quot;
  35. android:layout_marginTop=&quot;20dp&quot;
  36. android:layout_marginBottom=&quot;20dp&quot;
  37. android:orientation=&quot;vertical&quot;&gt;
  38. &lt;com.google.android.material.textfield.TextInputLayout
  39. android:layout_width=&quot;match_parent&quot;
  40. android:layout_height=&quot;wrap_content&quot;
  41. android:id=&quot;@+id/reg_name&quot;
  42. android:hint=&quot;Nama&quot;
  43. style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
  44. &lt;EditText
  45. android:layout_width=&quot;match_parent&quot;
  46. android:layout_height=&quot;wrap_content&quot;
  47. android:inputType=&quot;text&quot;/&gt;
  48. &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  49. &lt;com.google.android.material.textfield.TextInputLayout
  50. android:layout_width=&quot;match_parent&quot;
  51. android:layout_height=&quot;wrap_content&quot;
  52. android:id=&quot;@+id/reg_npm&quot;
  53. android:hint=&quot;NPM&quot;
  54. style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
  55. &lt;EditText
  56. android:layout_width=&quot;match_parent&quot;
  57. android:layout_height=&quot;wrap_content&quot;
  58. android:inputType=&quot;number&quot;/&gt;
  59. &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  60. &lt;com.google.android.material.textfield.TextInputLayout
  61. android:layout_width=&quot;match_parent&quot;
  62. android:layout_height=&quot;wrap_content&quot;
  63. android:id=&quot;@+id/reg_username&quot;
  64. android:hint=&quot;Username&quot;
  65. app:counterEnabled=&quot;true&quot;
  66. app:counterMaxLength=&quot;15&quot;
  67. style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
  68. &lt;EditText
  69. android:layout_width=&quot;match_parent&quot;
  70. android:layout_height=&quot;wrap_content&quot;/&gt;
  71. &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  72. &lt;com.google.android.material.textfield.TextInputLayout
  73. android:layout_width=&quot;match_parent&quot;
  74. android:layout_height=&quot;wrap_content&quot;
  75. android:id=&quot;@+id/reg_email&quot;
  76. android:hint=&quot;Email&quot;
  77. app:passwordToggleEnabled=&quot;true&quot;
  78. style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
  79. &lt;EditText
  80. android:layout_width=&quot;match_parent&quot;
  81. android:layout_height=&quot;wrap_content&quot;
  82. android:inputType=&quot;textEmailAddress&quot;/&gt;
  83. &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  84. &lt;com.google.android.material.textfield.TextInputLayout
  85. android:layout_width=&quot;match_parent&quot;
  86. android:layout_height=&quot;wrap_content&quot;
  87. android:id=&quot;@+id/reg_password&quot;
  88. android:hint=&quot;Password&quot;
  89. app:passwordToggleEnabled=&quot;true&quot;
  90. android:transitionName=&quot;password_tran&quot;
  91. style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
  92. &lt;EditText
  93. android:layout_width=&quot;match_parent&quot;
  94. android:layout_height=&quot;wrap_content&quot;
  95. android:inputType=&quot;textPassword&quot;/&gt;
  96. &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  97. &lt;com.google.android.material.textfield.TextInputLayout
  98. android:layout_width=&quot;match_parent&quot;
  99. android:layout_height=&quot;wrap_content&quot;
  100. android:id=&quot;@+id/reg_CoPassword&quot;
  101. android:hint=&quot;Confirm Password&quot;
  102. app:passwordToggleEnabled=&quot;true&quot;
  103. android:transitionName=&quot;coPassword_tran&quot;
  104. style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
  105. &lt;EditText
  106. android:layout_width=&quot;match_parent&quot;
  107. android:layout_height=&quot;wrap_content&quot;
  108. android:inputType=&quot;textPassword&quot;/&gt;
  109. &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  110. &lt;Button
  111. android:id=&quot;@+id/reg_btn&quot;
  112. android:layout_width=&quot;match_parent&quot;
  113. android:layout_height=&quot;wrap_content&quot;
  114. android:text=&quot;Register&quot;
  115. android:background=&quot;#000&quot;
  116. android:textColor=&quot;#FFF&quot;/&gt;
  117. &lt;Button
  118. android:id=&quot;@+id/reg_login_btn&quot;
  119. android:layout_width=&quot;match_parent&quot;
  120. android:layout_height=&quot;wrap_content&quot;
  121. android:text=&quot;Udah ada akun? Sign in sini&quot;
  122. android:background=&quot;#00000000&quot;
  123. android:textColor=&quot;#FFF&quot;/&gt;
  124. &lt;/LinearLayout&gt;
  125. &lt;ProgressBar
  126. android:id=&quot;@+id/signUp_progress&quot;
  127. android:layout_width=&quot;wrap_content&quot;
  128. android:layout_height=&quot;wrap_content&quot;
  129. android:visibility=&quot;gone&quot;/&gt;
  130. &lt;/LinearLayout&gt;

答案1

得分: 1

它报告 ClassCastException,因为您将 TextInputLayout 误当作 EditText 处理。为包装的 editText 设置单独的 id,并在该视图上调用 getText(),而不是调用 TextInputLayout 上的方法。

英文:

it says ClassCastException because you treat TextInputLayout as EditText. Set a separate id for for the wrapped editText and call getText() on that view instead.

huangapple
  • 本文由 发表于 2020年10月12日 23:55:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64321212.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定