我在firebase中执行查询时遇到错误,我的查询代码如下所示:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_perfil);
txtNome = (TextView) findViewById(R.id.txtNomePerfil);
txtCpf = (TextView) findViewById(R.id.txtCpfPerfil);
txtEmail = (TextView) findViewById(R.id.txtEmailPerfil);
txtFone = (TextView) findViewById(R.id.txtCelularPerfil);
txtPlaca = (TextView) findViewById(R.id.txtPlacaPerfil);
imgPerfil = (ImageView) findViewById(R.id.imgPerfil);
txtNomeFantasia = (TextView) findViewById(R.id.txtNomeFantasiaPerfil);
txtCnpj = (TextView) findViewById(R.id.txtCnpjPerfil);
firebaseUser = firebaseAuth.getInstance().getCurrentUser();
uId = firebaseUser.getUid();
email = firebaseUser.getEmail();
txtEmail.setText(email);
databaseReference = FirebaseDatabase.getInstance().getReference();
databaseReference.child("Usuario").child(uId).child("nome")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
nome = dataSnapshot.getValue(String.class);
txtNome.setText(nome);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
DatabaseReference mReferenceCpf = FirebaseDatabase.getInstance().getReference();
databaseReference.child("Usuario").child(uId).child("cnpjCpf")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
cpf = dataSnapshot.getValue(String.class);
txtCpf.setText(cpf);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
DatabaseReference mReferencePlaca = FirebaseDatabase.getInstance().getReference();
mReferencePlaca.child("Funcionario").child(cpf).child("placa")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
placa = dataSnapshot.getValue(String.class);
txtPlaca.setText(placa);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
但是我收到以下错误:
异常java.lang.RuntimeException:无法启动活动ComponentInfo
{ucarparceiro.ucarapp.com.ucarparceiro /
ucarparceiro.ucarapp.com.ucarparceiro.Activity.ActivityPrincipal.ActivityPerfil}:java.lang.NullPointerException:无法为参数’传递null
child()中的pathString’
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)android.app.ActivityThread.access
$ 800(ActivityThread.java:147)android.app.ActivityThread $ H
.handleMessage(ActivityThread.java:1281)android.os.Handler.dispatchMessage(Handler.java:102)android.os.Looper.loop(Looper.java:135)android.app.ActivityThread.main(ActivityThread.java:5253
)java.lang.reflect.Method.invoke(Method.java)java.lang.reflect.Method.invoke(Method.java:372)com.android.internal.os.ZygoteInit
$ MethodAndArgsCaller.run(ZygoteInit.java:899
)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Firebase中的数据如下:
用户
员工
您很可能会收到错误消息,因为cpf
当您将其用作中的子级时为null
mReferenceplaca
。发生这种情况是因为Firebase异步下载数据,并且您的代码行是同步执行的。因此,在mReferencePlaca.child("Funcionario").child(cpf).child("placa")
执行此行时,的值cpf
仍为null,因为这cpf = dataSnapshot.getValue(String.class);
尚未发生。
要解决此问题,请更改此:-
DatabaseReference mReferenceCpf = FirebaseDatabase.getInstance().getReference();
databaseReference.child("Usuario").child(uId).child("cnpjCpf")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
cpf = dataSnapshot.getValue(String.class);
txtCpf.setText(cpf);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
DatabaseReference mReferencePlaca = FirebaseDatabase.getInstance().getReference();
mReferencePlaca.child("Funcionario").child(cpf).child("placa")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
placa = dataSnapshot.getValue(String.class);
txtPlaca.setText(placa);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
为此:-
DatabaseReference mReferenceCpf = FirebaseDatabase.getInstance().getReference();
databaseReference.child("Usuario").child(uId).child("cnpjCpf")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
cpf = dataSnapshot.getValue(String.class);
txtCpf.setText(cps);
DatabaseReference mReferencePlaca = FirebaseDatabase.getInstance().getReference();
mReferencePlaca.child("Funcionario").child(cpf).child("placa")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
placa = dataSnapshot.getValue(String.class);
txtPlaca.setText(placa);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Utility method Converts path to a new path where all segments are cubic beziér curves Parameters pathStringstringarraypath string or array of segments Returns: array array of segments
Creates a <path> element using the given string as the path's definition Parameters pathStringstringpath string in SVG format Path string consists of one-letter commands, followed by comma seprarated
Utility method Parses given path string into an array of arrays of path segments Parameters pathStringstringarraypath string or array of segments (inthe last case it is returned straightaway) Returns:
这个问题的解决方案是什么?问题在这里,代码在这里: > 列表项 在BindViewHolder上公开无效(@nonNull HolderOrderShop持有人,int位置){ //转换时间日历=日历。getInstance();日历setTimeInMillis(Long.parseLong(orderTime));String formattedate=DateFormat。格式(“日/月/年
我们已经讨论了如何使用指针实现call by reference概念。 这是另一个通过引用调用的例子,它使用C ++引用 - #include <iostream> using namespace std; // function declaration void swap(int& x, int& y); int main () { // local variable declaratio
问题内容: 是否可以通过以参数作为参数的javascript函数? 例: 问题答案: 使用“关闭”: 这将创建一个匿名的临时函数包装器,该包装器知道该参数并将其传递给实际的回调实现。