无法在Android Studio中连接到Firebase时找不到符号。

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

cannot find symbol in android studio while connecting to firebase

问题

当我尝试连接我的应用程序到数据库时,显示了一个找不到符号的错误。

错误:找不到符号
String ownerName = ownerName.getEditText().getText().toString();
^
符号: 方法 getEditText()
位置: 类型为 String 的变量 ownerName

以下是我的代码:

public class merchantRegistrationForm extends AppCompatActivity implements View.OnClickListener {
    EditText ownerName, phoneNumber, emailId, password, cnfPassword;

    DatabaseReference databaseReference;
    FirebaseAuth firebaseAuth;
    FirebaseDatabase rootNode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_merchant_registration_form);

        ownerName = findViewById(R.id.ownerName);
        phoneNumber = findViewById(R.id.ownerPhoneNumber);
        emailId = findViewById(R.id.ownerEmailId);
        password =findViewById(R.id.password);
        cnfPassword =findViewById(R.id.confirmPassword);

        Button goNext;
        goNext = findViewById(R.id.nextToBusinessSelector);
        goNext.setOnClickListener(this);

        databaseReference = FirebaseDatabase.getInstance().getReference("merchant Signup");

        goNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rootNode = FirebaseDatabase.getInstance();
                databaseReference = rootNode.getReference();
                String ownerName = ownerName.getEditText().getText().toString();
                String phoneNumber = phoneNumber.getEditText().getText().toString();
                String emailId = emailId.getEditText().getText().toString();
                String password = password.getEditText().getText().toString();
                String cnfPassword = cnfPassword.getEditText().getText().toString();
                merchantsignup helperclass = new merchantsignup(ownerName, phoneNumber,emailId, password, cnfPassword);

                databaseReference.setValue("hello");
            }
        });

        Intent intent = new Intent(merchantRegistrationForm.this, salonDetails.class);
        startActivity(intent);
        Toast.makeText(this, "Few Steps more", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onClick(View view) {

    }
}
英文:

When I am trying to connect my app to the database it is showing an error of cannot find symbol.

error: cannot find symbol
String ownerName = ownerName.getEditText().getText().toString();
^
symbol:   method getEditText()
location: variable ownerName of type String

below is my code

public class merchantRegistrationForm extends AppCompatActivity implements View.OnClickListener {
EditText ownerName, phoneNumber, emailId, password, cnfPassword;
DatabaseReference databaseReference;
FirebaseAuth firebaseAuth;
FirebaseDatabase rootNode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_merchant_registration_form);
ownerName = findViewById(R.id.ownerName);
phoneNumber = findViewById(R.id.ownerPhoneNumber);
emailId = findViewById(R.id.ownerEmailId);
password =findViewById(R.id.password);
cnfPassword =findViewById(R.id.confirmPassword);
Button goNext;
goNext = findViewById(R.id.nextToBusinessSelector);
goNext.setOnClickListener(this);
databaseReference = FirebaseDatabase.getInstance().getReference("merchant Signup");
goNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rootNode = FirebaseDatabase.getInstance();
databaseReference = rootNode.getReference();
String ownerName = ownerName.getEditText().getText().toString();
String phoneNumber = phoneNumber.getEditText().getText().toString();
String emailId = emailId.getEditText().getText().toString();
String password = password.getEditText().getText().toString();
String cnfPassword = cnfPassword.getEditText().getText().toString();
merchantsignup helperclass = new merchantsignup(ownerName, phoneNumber,emailId, password, cnfPassword);
databaseReference.setValue("hello");
}
});
Intent intent = new Intent(merchantRegistrationForm.this, salonDetails.class);
startActivity(intent);
Toast.makeText(this, "Few Steps more", Toast.LENGTH_LONG).show();
}
@Override
public void onClick(View view) {
}
}

答案1

得分: 1

你的代码令人困惑,因为你最初将 ownerName 声明为一个 EditText:

EditText ownerName;

但后来又将其重新定义为一个字符串:

String ownerName = ownerName.getEditText().getText().toString();

错误信息提示你在字符串对象上没有 getEditText() 方法。也许你想为字符串变量使用不同的名称。

英文:

Your code is confusing because you initially declare ownerName as an EditText:

EditText ownerName;

But then redefined it as a string:

String ownerName = ownerName.getEditText().getText().toString();

The error message is telling you that there is no method getEditText() on a String object. Perhaps you want to use a different name for the string variable.

huangapple
  • 本文由 发表于 2020年9月18日 03:50:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63945292.html
匿名

发表评论

匿名网友

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

确定