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

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

Firebase Custom Userfield crash - Android Studio

问题

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

public class SignUp extends AppCompatActivity {

    //变量
    private EditText regName, regNpm, regUsername, regEmail, regPassword, regCoPassword;
    private Button regBtn, regToLoginBtn;
    ProgressBar signUp_progress;

    private DatabaseReference databaseReference;
    private FirebaseDatabase firebaseDatabase;
    private FirebaseAuth mAuth;

    String fullname, username, email, npm, password, co_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_sign_up);

        signUp_progress = findViewById(R.id.signUp_progress);
        regName = findViewById(R.id.reg_name);
        regNpm = findViewById(R.id.reg_npm);
        regUsername = findViewById(R.id.reg_username);
        regEmail = findViewById(R.id.reg_email);
        regPassword = findViewById(R.id.reg_password);
        regCoPassword = findViewById(R.id.reg_CoPassword);
        regBtn = findViewById(R.id.reg_btn);
        regToLoginBtn = findViewById(R.id.reg_login_btn);

        mAuth = FirebaseAuth.getInstance();
        firebaseDatabase = FirebaseDatabase.getInstance();
        databaseReference = firebaseDatabase.getReference("UserData");

        regToLoginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), Login.class);
                startActivity(intent);
            }
        });

        regBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!validateFullname() | !validateUsername() | !validateEmail() | !validatePassword() | !validateNpm()) {
                    return;
                }

                if (regPassword.equals(regCoPassword)) {
                    signUp_progress.setVisibility(View.VISIBLE);
                    mAuth.createUserWithEmailAndPassword(email, String.valueOf(regPassword)).addOnCompleteListener
                            (new OnCompleteListener<AuthResult>() {
                                @Override
                                public void onComplete(@NonNull Task<AuthResult> task) {
                                    if (task.isSuccessful()) {
                                        UserData data = new UserData(fullname, username, email, npm);
                                        FirebaseDatabase.getInstance().getReference("UserData")
                                                .child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(data).
                                                addOnCompleteListener(new OnCompleteListener<Void>() {
                                                    @Override
                                                    public void onComplete(@NonNull Task<Void> task) {
                                                        signUp_progress.setVisibility(View.GONE);
                                                        Toast.makeText(SignUp.this, "Successful Registered", Toast.LENGTH_SHORT).show();
                                                        Intent intent = new Intent(SignUp.this, MenuActivity.class);
                                                        startActivity(intent);
                                                        finish();
                                                    }
                                                });
                                    } else {
                                        signUp_progress.setVisibility(View.GONE);
                                        Toast.makeText(SignUp.this, "Check Email id or Password", Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                } else {
                    Toast.makeText(SignUp.this, "Password didn't match", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    // 省略其他部分...
}
public class Login extends AppCompatActivity {

    Button callSignUp, loginBtn;
    ImageView image;
    TextView logoText, sloganText;
    TextInputLayout username, password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_login);

        callSignUp = findViewById(R.id.signup_screen);
        image = findViewById(R.id.logo_image);
        logoText = findViewById(R.id.logo_text);
        sloganText = findViewById(R.id.slogan_text);
        username = findViewById(R.id.username);
        password = findViewById(R.id.password);
        loginBtn = findViewById(R.id.login_btn);

        callSignUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Login.this,SignUp.class);
                Pair[] pairs = new Pair[7];
                pairs[0] = new Pair<View,String>(image,"logo_image");
                pairs[1] = new Pair<View,String>(logoText,"logo_text");
                pairs[2] = new Pair<View,String>(sloganText,"logo_desc");
                pairs[3] = new Pair<View,String>(username,"uname_tran");
                pairs[4] = new Pair<View,String>(password,"password_tran");
                pairs[5] = new Pair<View,String>(loginBtn,"button_tran");
                pairs[6] = new Pair<View,String>(callSignUp,"login_signup_tran");
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Login.this,pairs);
                startActivity(intent, options.toBundle());
            }
        });
    }
}

以上是代码的翻译部分,包括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

public class SignUp extends AppCompatActivity {
//Variabel
private EditText regName, regNpm, regUsername, regEmail, regPassword, regCoPassword;
private Button regBtn, regToLoginBtn;
ProgressBar signUp_progress;
private DatabaseReference databaseReference;
private FirebaseDatabase firebaseDatabase;
private FirebaseAuth mAuth;
String fullname, username, email, npm, password, co_password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Line dibawah untuk menghilangkan status bar dari screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sign_up);
//Hooks ke semua elemen xml di activity_sign_up.xml
signUp_progress = findViewById(R.id.signUp_progress);
regName = findViewById(R.id.reg_name);
regNpm = findViewById(R.id.reg_npm);
regUsername = findViewById(R.id.reg_username);
regEmail = findViewById(R.id.reg_email);
regPassword = findViewById(R.id.reg_password);
regCoPassword = findViewById(R.id.reg_CoPassword);
regBtn = findViewById(R.id.reg_btn);
regToLoginBtn = findViewById(R.id.reg_login_btn);
//        Get Firebase auth instance
mAuth = FirebaseAuth.getInstance();
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference(&quot;UserData&quot;);
regToLoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Login.class);
startActivity(intent);
}
});
//        handle user SignUp button
regBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!validateFullname() | !validateUsername() | !validateEmail() | !validatePassword() | !validateNpm()) {
return;
}
if (regPassword.equals(regCoPassword)) {
//    progressbar VISIBLE
signUp_progress.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email, String.valueOf(regPassword)).addOnCompleteListener
(new OnCompleteListener&lt;AuthResult&gt;() {
@Override
public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
if (task.isSuccessful()) {
UserData data = new UserData(fullname, username, email, npm);
FirebaseDatabase.getInstance().getReference(&quot;UserData&quot;)
.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(data).
addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
@Override
public void onComplete(@NonNull Task&lt;Void&gt; task) {
//    progressbar GONE
signUp_progress.setVisibility(View.GONE);
Toast.makeText(SignUp.this, &quot;Successful Registered&quot;, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(SignUp.this, MenuActivity.class);
startActivity(intent);
finish();
}
});
} else {
//    progressbar GONE
signUp_progress.setVisibility(View.GONE);
Toast.makeText(SignUp.this, &quot;Check Email id or Password&quot;, Toast.LENGTH_SHORT).show();
}
}
});
} else {
Toast.makeText(SignUp.this, &quot;Password didn&#39;t match&quot;, Toast.LENGTH_SHORT).show();
}
}
});
}
private boolean validateFullname() {
fullname = regName.getText().toString().trim();
if (TextUtils.isEmpty(fullname)) {
Toast.makeText(SignUp.this, &quot;Enter Your Full Name&quot;, Toast.LENGTH_SHORT).show();
return false;
} else {
return true;
}
}
private boolean validateUsername() {
username = regUsername.getText().toString().trim();
if (TextUtils.isEmpty(username)) {
Toast.makeText(SignUp.this, &quot;Enter Your User Name&quot;, Toast.LENGTH_SHORT).show();
return false;
} else {
return true;
}
}
private boolean validateNpm() {
npm = regNpm.getText().toString().trim();
if (TextUtils.isEmpty(npm)) {
Toast.makeText(SignUp.this, &quot;Enter Your NPM&quot;, Toast.LENGTH_SHORT).show();
return false;
} else {
return true;
}
}
private boolean validateEmail() {
email = regEmail.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
Toast.makeText(SignUp.this, &quot;Enter Your Email&quot;, Toast.LENGTH_SHORT).show();
return false;
} else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
Toast.makeText(SignUp.this, &quot;Please enter valid Email&quot;, Toast.LENGTH_SHORT).show();
return false;
} else {
return true;
}
}
private boolean validatePassword() {
password  = regPassword.getText().toString().trim();
co_password = regCoPassword.getText().toString().toLowerCase();
if (TextUtils.isEmpty(password)) {
Toast.makeText(SignUp.this, &quot;Enter Your Password&quot;, Toast.LENGTH_SHORT).show();
return false;
} else if (TextUtils.isEmpty(co_password)) {
Toast.makeText(SignUp.this, &quot;Enter Your Co-Password&quot;, Toast.LENGTH_SHORT).show();
return false;
} else if (password.length() &lt;= 6) {
Toast.makeText(SignUp.this, &quot;Password is Very Short&quot;, Toast.LENGTH_SHORT).show();
return false;
} else {
return true;
}
}
//    if the user already logged in then it will automatically send on Dashboard/MainActivity activity.
@Override
public void onStart() {
super.onStart();
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
Intent intent = new Intent(SignUp.this, MenuActivity.class);
startActivity(intent);
}
}

}

And this is the listing code from Login.java

public class Login extends AppCompatActivity {
//Variabel
Button callSignUp, loginBtn;
ImageView image;
TextView logoText, sloganText;
TextInputLayout username, password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Line dibawah untuk menghilangkan status bar dari screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
//Hooks
callSignUp = findViewById(R.id.signup_screen);
image = findViewById(R.id.logo_image);
logoText = findViewById(R.id.logo_text);
sloganText = findViewById(R.id.slogan_text);
username = findViewById(R.id.username);
password = findViewById(R.id.password);
loginBtn = findViewById(R.id.login_btn);
callSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Login.this,SignUp.class);
Pair[] pairs = new Pair[7];
pairs [0] = new Pair&lt;View,String&gt;(image,&quot;logo_image&quot;);
pairs [1] = new Pair&lt;View,String&gt;(logoText,&quot;logo_text&quot;);
pairs [2] = new Pair&lt;View,String&gt;(sloganText,&quot;logo_desc&quot;);
pairs [3] = new Pair&lt;View,String&gt;(username,&quot;uname_tran&quot;);
pairs [4] = new Pair&lt;View,String&gt;(password,&quot;password_tran&quot;);
pairs [5] = new Pair&lt;View,String&gt;(loginBtn,&quot;button_tran&quot;);
pairs [6] = new Pair&lt;View,String&gt;(callSignUp,&quot;login_signup_tran&quot;);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Login.this,pairs);
startActivity(intent, options.toBundle());
}
});
}

}

And then there's logcat

2020-10-13 00:24:08.213 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
2020-10-13 00:24:08.225 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
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)
2020-10-13 00:24:08.230 5297-5336/com.hardy.gunadarmastudentapp E/Surface: IGraphicBufferProducer::setBufferCount(3) returned Invalid argument
2020-10-13 00:24:08.231 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
2020-10-13 00:24:08.240 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
2020-10-13 00:24:08.244 5297-5336/com.hardy.gunadarmastudentapp D/EGL_emulation: eglMakeCurrent: 0x77c26384a380: ver 2 0 (tinfo 0x77c2f32f8280)
2020-10-13 00:24:08.251 5297-5297/com.hardy.gunadarmastudentapp W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@5690764
2020-10-13 00:24:08.257 5297-5333/com.hardy.gunadarmastudentapp V/FA: onActivityCreated
2020-10-13 00:24:08.259 5297-5339/com.hardy.gunadarmastudentapp V/FA: Recording user engagement, ms: 12594
2020-10-13 00:24:08.261 5297-5339/com.hardy.gunadarmastudentapp V/FA: Connecting to remote service
2020-10-13 00:24:08.267 5297-5339/com.hardy.gunadarmastudentapp V/FA: Activity paused, time: 130626
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.
2020-10-13 00:24:08.312 5297-5297/com.hardy.gunadarmastudentapp I/chatty: uid=10134(com.hardy.gunadarmastudentapp) identical 4 lines
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.
2020-10-13 00:24:08.332 5297-5339/com.hardy.gunadarmastudentapp V/FA: Connection attempt already in progress
2020-10-13 00:24:08.576 5297-5297/com.hardy.gunadarmastudentapp D/AndroidRuntime: Shutting down VM
2020-10-13 00:24:09.200 5297-5297/com.hardy.gunadarmastudentapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hardy.gunadarmastudentapp, PID: 5297
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
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to android.widget.EditText
at com.hardy.gunadarmastudentapp.SignUp.onCreate(SignUp.java:47)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)&#160;
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)&#160;
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)&#160;
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)&#160;
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)&#160;
at android.os.Handler.dispatchMessage(Handler.java:107)&#160;
at android.os.Looper.loop(Looper.java:214)&#160;
at android.app.ActivityThread.main(ActivityThread.java:7356)&#160;
at java.lang.reflect.Method.invoke(Native Method)&#160;
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)&#160;
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)&#160;
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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
tools:context=&quot;.SignUp&quot;
android:orientation=&quot;vertical&quot;
android:background=&quot;#8f4dc9&quot;
android:padding=&quot;20dp&quot;&gt;
&lt;ImageView
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:transitionName=&quot;logo_image&quot;
android:src=&quot;@drawable/logogundar&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/logo_name&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:fontFamily=&quot;@font/acme&quot;
android:text=&quot;Menu Register&quot;
android:textSize=&quot;30sp&quot;
android:transitionName=&quot;logo_text&quot;
android:textColor=&quot;#FFF&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/slogan_name&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Isi NPM, username, dan email untuk sign in&quot;
android:textColor=&quot;#FFF&quot;
android:textSize=&quot;15sp&quot;/&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;20dp&quot;
android:layout_marginBottom=&quot;20dp&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;com.google.android.material.textfield.TextInputLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/reg_name&quot;
android:hint=&quot;Nama&quot;
style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
&lt;EditText
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:inputType=&quot;text&quot;/&gt;
&lt;/com.google.android.material.textfield.TextInputLayout&gt;
&lt;com.google.android.material.textfield.TextInputLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/reg_npm&quot;
android:hint=&quot;NPM&quot;
style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
&lt;EditText
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:inputType=&quot;number&quot;/&gt;
&lt;/com.google.android.material.textfield.TextInputLayout&gt;
&lt;com.google.android.material.textfield.TextInputLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/reg_username&quot;
android:hint=&quot;Username&quot;
app:counterEnabled=&quot;true&quot;
app:counterMaxLength=&quot;15&quot;
style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
&lt;EditText
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;/&gt;
&lt;/com.google.android.material.textfield.TextInputLayout&gt;
&lt;com.google.android.material.textfield.TextInputLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/reg_email&quot;
android:hint=&quot;Email&quot;
app:passwordToggleEnabled=&quot;true&quot;
style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
&lt;EditText
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:inputType=&quot;textEmailAddress&quot;/&gt;
&lt;/com.google.android.material.textfield.TextInputLayout&gt;
&lt;com.google.android.material.textfield.TextInputLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/reg_password&quot;
android:hint=&quot;Password&quot;
app:passwordToggleEnabled=&quot;true&quot;
android:transitionName=&quot;password_tran&quot;
style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
&lt;EditText
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:inputType=&quot;textPassword&quot;/&gt;
&lt;/com.google.android.material.textfield.TextInputLayout&gt;
&lt;com.google.android.material.textfield.TextInputLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/reg_CoPassword&quot;
android:hint=&quot;Confirm Password&quot;
app:passwordToggleEnabled=&quot;true&quot;
android:transitionName=&quot;coPassword_tran&quot;
style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;&gt;
&lt;EditText
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:inputType=&quot;textPassword&quot;/&gt;
&lt;/com.google.android.material.textfield.TextInputLayout&gt;
&lt;Button
android:id=&quot;@+id/reg_btn&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Register&quot;
android:background=&quot;#000&quot;
android:textColor=&quot;#FFF&quot;/&gt;
&lt;Button
android:id=&quot;@+id/reg_login_btn&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Udah ada akun? Sign in sini&quot;
android:background=&quot;#00000000&quot;
android:textColor=&quot;#FFF&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;ProgressBar
android:id=&quot;@+id/signUp_progress&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:visibility=&quot;gone&quot;/&gt;
&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:

确定