Android 从firebase检索数据时查看PostIME 0,1错误
这里我试图显示当前登录用户的数据。如果有任何其他方法检索数据,请共享 这是我的数据库: 这是我用来保存数据的代码:Android 从firebase检索数据时查看PostIME 0,1错误,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,这里我试图显示当前登录用户的数据。如果有任何其他方法检索数据,请共享 这是我的数据库: 这是我用来保存数据的代码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); setContentView(R.layout.activi
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_signup);
mfirebase = FirebaseAuth.getInstance();
msuser=(EditText)findViewById(R.id.signup_username);
mspass=(EditText)findViewById(R.id.signup_password);
mloginn=(TextView)findViewById(R.id.already);
msconfpass=(EditText)findViewById(R.id.confirm_password);
uname=(EditText)findViewById(R.id.uname);
ugender=(EditText)findViewById(R.id.ugender);
uheight=(EditText)findViewById(R.id.uheight);
uweight=(EditText)findViewById(R.id.uweight);
ud= new UserDetails();
reference=FirebaseDatabase.getInstance().getReference().child("User");
msave=(Button)findViewById(R.id.save);
msave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//n
String uName= uname.getText().toString().trim();
Float uHeight = Float.parseFloat(uheight.getText().toString().trim());
Float uWeight = Float.parseFloat(uweight.getText().toString().trim());
String uGender= ugender.getText().toString().trim();
String uEmail= msuser.getText().toString().trim();
ud.setName(uName);
ud.setHeight(uHeight);
ud.setWeight(uWeight);
ud.setGender(uGender);
ud.setEmail(uEmail);
reference.push().setValue(ud);
//n
email= msuser.getText().toString();
String pwd=mspass.getText().toString();
String cpwd=msconfpass.getText().toString();
if(email.isEmpty()){
msuser.setError("Please enter email id");
msuser.requestFocus();
}
else if(pwd.isEmpty()){
mspass.setError("Please enter the password");
mspass.requestFocus();
}
else if(cpwd.isEmpty()){
msconfpass.setError("Please enter password again");
msconfpass.requestFocus();
}
else if(email.isEmpty() && pwd.isEmpty() && cpwd.isEmpty()){
Toast.makeText(Signup.this,"Fields are empty",Toast.LENGTH_SHORT).show();
}
else if(!cpwd.equals(pwd)){
Toast.makeText(Signup.this,"Please enter same password",Toast.LENGTH_SHORT).show();
}
else if(!(email.isEmpty() && pwd.isEmpty() && cpwd.isEmpty())){
mfirebase.createUserWithEmailAndPassword(email,pwd).addOnCompleteListener(Signup.this, new OnCompleteListener<com.google.firebase.auth.AuthResult>() {
@Override
public void onComplete(@NonNull Task<com.google.firebase.auth.AuthResult> task) {
if(!task.isSuccessful()){
Toast.makeText(Signup.this,"Signup Unsuccessful",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Signup.this,"Account Created Successfully and You're now logged in",Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(Signup.this,Login.class));
//Toast.makeText(Signup.this,"Account Created Successfully",Toast.LENGTH_SHORT).show();
}
}
});
}
else{
Toast.makeText(Signup.this,"Error",Toast.LENGTH_SHORT).show();
}
}
});
这是单击showb(用于在文本字段中显示的按钮)后显示的错误:
单击showb后,错误如下:
2020-04-01 19:28:18.285 7996-7996/com.zzz.fitness D/ViewRootImpl@133c623[UserProfile]: ViewPostIme pointer 0
2020-04-01 19:28:18.359 7996-7996/com.zz.fitness D/ViewRootImpl@133c623[UserProfile]: ViewPostIme pointer 1
您正在随机id下存储值:
reference.push().setValue(ud);
此代码生成一个随机id,在该id下您将具有classUserDetails
的属性,您需要将其更改为以下内容:
mfirebase.createUserWithEmailAndPassword(email,pwd).addOnCompleteListener(Signup.this, new OnCompleteListener<com.google.firebase.auth.AuthResult>() {
@Override
public void onComplete(@NonNull Task<com.google.firebase.auth.AuthResult> task) {
if(!task.isSuccessful()){
Toast.makeText(Signup.this,"Signup Unsuccessful",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Signup.this,"Account Created Successfully and You're now logged in",Toast.LENGTH_SHORT).show();
reference.child(task.getResult().getUser().getUid()).setValue(ud); //add this line
finish();
startActivity(new Intent(Signup.this,Login.class));
//Toast.makeText(Signup.this,"Account Created Successfully",Toast.LENGTH_SHORT).show();
}
您正在随机id下存储值:
reference.push().setValue(ud);
此代码生成一个随机id,在该id下您将具有classUserDetails
的属性,您需要将其更改为以下内容:
mfirebase.createUserWithEmailAndPassword(email,pwd).addOnCompleteListener(Signup.this, new OnCompleteListener<com.google.firebase.auth.AuthResult>() {
@Override
public void onComplete(@NonNull Task<com.google.firebase.auth.AuthResult> task) {
if(!task.isSuccessful()){
Toast.makeText(Signup.this,"Signup Unsuccessful",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Signup.this,"Account Created Successfully and You're now logged in",Toast.LENGTH_SHORT).show();
reference.child(task.getResult().getUser().getUid()).setValue(ud); //add this line
finish();
startActivity(new Intent(Signup.this,Login.class));
//Toast.makeText(Signup.this,"Account Created Successfully",Toast.LENGTH_SHORT).show();
}
如何验证用户是否已登录?如何验证用户是否已登录?此登录:[reference.child(task.getResult().getUser().getUid()).setValue(ud);]!task.isSuccessful(未成功)部分还是成功创建帐户的else部分?Cz我试过了,它给了我同样的错误@Peter Haddad请检查编辑,也不要忘记删除
reference.push().setValue(ud)代码>我已经从showb按钮中删除了代码,并在onCreate中发布了代码。它可以工作,但打开“活动”后需要一秒或两秒才能加载。这里的问题是什么,为什么不立即解决?。每次我打开活动时都会发生。我能做些什么来加快加载速度@Peter Haddad它是异步的,当然这需要一点时间,如果你有坏的CinectionOkay,甚至更多。好吧,我会添加一个进度条(加载图标),这样看起来会更好。再次感谢。这在:[reference.child(task.getResult().getUser().getUid()).setValue(ud);]中!task.isSuccessful(未成功)部分还是成功创建帐户的else部分?Cz我试过了,它给了我同样的错误@Peter Haddad请检查编辑,也不要忘记删除reference.push().setValue(ud)代码>我已经从showb按钮中删除了代码,并在onCreate中发布了代码。它可以工作,但打开“活动”后需要一秒或两秒才能加载。这里的问题是什么,为什么不立即解决?。每次我打开活动时都会发生。我能做些什么来加快加载速度@Peter Haddad它是异步的,当然这需要一点时间,如果你有坏的CinectionOkay,甚至更多。好吧,我会添加一个进度条(加载图标),这样看起来会更好。再次感谢。