@Override
protected void onStart() {
super.onStart();
databaseVaccine.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String k;
vaccineList.clear();
for(
DataSnapshot vaccineSnapshot :dataSnapshot.getChildren())
{
//getting farm
Vaccine vaccine = vaccineSnapshot.getValue(Vaccine.class);
k= getSfuff();
if (vaccine.CattleVaccineID.equals(k)) {
vaccineList.add(vaccine);
}
//adding farm to the list
}
VaccineList adapters = new VaccineList(ViewVaccination.this, vaccineList);
ListViewVaccine.setAdapter(adapters);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
public String getSfuff() {
Bundle bundle = getIntent().getExtras();
String stuff = bundle.getString("cattleID");
return stuff;
}
正在显示以下错误
“ if(vaccine.CattleVaccineID.equals(k))”
java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'boolean java.lang.String.equals(java.lang.Object)'
有人可以找到解决此错误的解决方案吗?我尝试了许多选项,但这些选项无法正常工作。
@@覆盖受保护的void onStart(){super.onStart(); databaseVaccine.addValueEventListener(new ValueEventListener(){@Override public void onDataChange(@ ...