英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论