我已经给出了firebase的插入代码,但是没有将数据插入到firebase数据库中。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_newregistration);
UserName = findViewById(R.id.UserName);
Empid = findViewById(R.id.Empid);
phoneno = findViewById(R.id.Phoneno);
Emailid = findViewById(R.id.Emailid);
Newpassword = findViewById(R.id.newpassword);
btn_back = findViewById(R.id.btn_back);
btnreg = findViewById(R.id.btnreg);
member= new Member();
reff= FirebaseDatabase.getInstance().getReference().child("Member");
reff.addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists())
maxid=(dataSnapshot.getChildrenCount());
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
btnreg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reff.child(String.valueOf(maxid+1)).setValue(member);
member.setUserName(UserName.getText().toString().trim());
member.setEmailid(Emailid.getText().toString().trim());
member.setEmpid(Empid.getText().toString().trim());
member.setPhoneno(phoneno.getText().toString().trim());
member.setNewpassword(Newpassword.getText().toString().trim());
Toast.makeText(Newregistration.this,"Data Inserted Succesfully",Toast.LENGTH_LONG).show();
startActivity(new Intent(Newregistration.this, LoginActivity.class));
}
});
btn_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Newregistration.this, LoginActivity.class));
}
});
}
}
当我们点击注册时,应用程序崩溃了,预期结果应插入到Firebase实时数据库中。
答案 0 :(得分:0)
setValue(member)