android.support.v7.widget.AppCompatEditText错误

时间:2017-10-14 16:26:05

标签: java android firebase

错误:

  

android.support.v7.widget.AppCompatEditText {8701551bVFED..CL。   ....... 484,0-747,118#7f0b006c app:id / name_text

我正在尝试将用户的姓名信息设置为FirebaseUser" DisplayName"在注册期间。我是android,java和firebase的新手。但是,尽管我进行了所有研究,但无法找到任何解决方案。 id / name_text是编辑文本,它在注册时从用户获取名称。我认为这是一个字符串问题,但无法解决。

帮助。感谢。

以下是代码。

public class RegisterActivity extends AppCompatActivity {

    @BindView(R.id.register_button) Button mRegisterButton;
    @BindView(R.id.surname_edittext) EditText mSurnameEditText;
    @BindView(R.id.name_text) EditText mNameEditText;
    @BindView(R.id.password_edittext) EditText mPasswordEditText;
    @BindView(R.id.mail_edittext) EditText mMailEditText;

    private FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
        mAuth = FirebaseAuth.getInstance();


    }

    @OnClick(R.id.register_button)
    public void register_button(View view){
        RegisterUser();
    }

    private void RegisterUser() {
        String surname = mSurnameEditText.getText().toString().trim();
        String name = mNameEditText.getText().toString().trim();
        String password = mPasswordEditText.getText().toString().trim();
        String mail = mMailEditText.getText().toString().trim();

        if (TextUtils.isEmpty(name)) {
            Toast.makeText(this, "enter the name", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(surname)) {
            Toast.makeText(this, "enter the surname", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(this, "enter the password", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(mail)) {
            Toast.makeText(this, "enter the mail", Toast.LENGTH_SHORT).show();
            return;
        }

        mAuth.createUserWithEmailAndPassword(mail,password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()){
                            Toast.makeText(RegisterActivity.this,"Successfully",Toast.LENGTH_SHORT).show();
                            savetheinfo();
                        }
                        else{
                            Toast.makeText(RegisterActivity.this,"Could not registered , please try again...",Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }

    private void savetheinfo() {
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                .setDisplayName(String.valueOf(mNameEditText)).build();
        user.updateProfile(profileUpdates);
    }
}


public class ProfileActivity extends AppCompatActivity {

    @BindView(R.id.user_name) TextView mUserName;
    private FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);
        ButterKnife.bind(this);
        mAuth = FirebaseAuth.getInstance();

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        setDataToView(user);
    }

    private void setDataToView(FirebaseUser user) {
        mUserName.setText(user.getDisplayName());
    }

}




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center"
              android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="24dp"
        android:text="REGISTER"
        android:layout_marginBottom="50dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name:     "/>

        <EditText
            android:id="@+id/name_text"
            android:layout_width="100dp"
            android:layout_height="wrap_content" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Surname:     "/>

        <EditText
            android:id="@+id/surname_edittext"
            android:layout_width="100dp"
            android:layout_height="wrap_content" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Mail:     "/>

        <EditText
            android:id="@+id/mail_edittext"
            android:layout_width="100dp"
            android:layout_height="wrap_content" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Password:     "/>

        <EditText
            android:id="@+id/password_edittext"
            android:layout_width="100dp"
            android:layout_height="wrap_content" />

    </LinearLayout>
    <Button
        android:id="@+id/register_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Register"
        android:layout_marginTop="50dp"/>

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

如果视图不为null,则

String.valueOf(mNameEditText)等效于mNameEditText.toString()。您可能正在寻找mNameEditText.getText().toString(),它会为您提供EditText元素的内容

答案 1 :(得分:0)

我能够通过以下方式解决此问题:

我只是使用了mNameEditText.getText().toString()。我忘了介于两者之间的.getText()