datasNapShot无法正常工作。
我正在我的Android项目中实施燃料。但是看来该函数datasNapShot并未初始化。它以红色下划线。
这是我的.java的代码,
table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(dataSnapshot.child(edtphone.getText().toString()).exists()) {
mDialog.dismiss();
User user = dataSnapshot.child(edtphone.getText().toString()).getValue(User.class);
if (user.getPassword().equals(edtpass.getText().toString())) {
Toast.makeText(signin.this, "Sign In Successful",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(signin.this, "Sign In Failed",
Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(signin.this, "User Not Found",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
我的两个datasnapshot函数都无法正常工作。 我已经尝试将其更改为DataSnapShot,但是.Child
不起作用
是否有此功能的更新或其他语法可以尝试?
更改为DataSnapShot返回此错误
非静态方法'child(java.lang.string)'无法从静态上下文中引用
I am implementing Firebase in my Android Project. But it seems that the function dataSnapshot is not being initialized. It is underlined in red.
Here is the Code for my .java
table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(dataSnapshot.child(edtphone.getText().toString()).exists()) {
mDialog.dismiss();
User user = dataSnapshot.child(edtphone.getText().toString()).getValue(User.class);
if (user.getPassword().equals(edtpass.getText().toString())) {
Toast.makeText(signin.this, "Sign In Successful",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(signin.this, "Sign In Failed",
Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(signin.this, "User Not Found",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
Both of my dataSnapshot functions are not working.
I have tried changing it to DataSnapshot but then the .child
is not working
Is there an update for this function or a different syntax to try?
Changing to DataSnapshot returns this error
Non-static method 'child(java.lang.String)' cannot be referenced from a static context
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的OnDataChange()有一个称为
快照
和不是datasNapShot
的参数,因此该错误:您要做的就是用
datasNapshot
使用snapshot
更改所有出现:Your onDataChange() has an argument called
snapshot
and notdataSnapshot
, hence that error:What you have to do is to change all occurrences of
dataSnapshot
withsnapshot
:The following operation will also not work:
Because the
child()
method is an instance method and not a static method.