0
Could someone help me? The app recovers data from child("grupos")
in debugging, but when I tie the knot, for example, child("grupos").child("nome")
, the application of crash nor in debugging to see if you’re recovering. What I’m doing wrong?
Database https://ibb.co/C1Gy8gs
DEBUG https://ibb.co/6b8Whw3
Error using child("groupos").child("nome");
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Iterator java.util.ArrayList.iterator()' on a null object reference
.activity.SalasActivity$1.search(SalasActivity.java:86)
.activity.SalasActivity$1.access$000(SalasActivity.java:56)
.activity.SalasActivity$1$1.onQueryTextChange(SalasActivity.java:78)
public class SalasActivity extends AppCompatActivity {
DatabaseReference ref;
ArrayList<Deal> list;
RecyclerView recyclerView;
SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_salas);
ref = FirebaseDatabase.getInstance().getReference().child("grupos").child("nome");
recyclerView = findViewById(R.id.rv);
searchView = findViewById(R.id.searchView);
}
@Override
protected void onStart() {
super.onStart();
if(ref != null){
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
list = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren())
{
list.add(ds.getValue(Deal.class));
}
AdapterClass adapterClass = new AdapterClass(list);
recyclerView.setAdapter(adapterClass);
}
if (searchView != null){
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
search(s);
return true;
}
});
}
}
private void search(String str){
ArrayList<Deal> myList = new ArrayList<>();
for (Deal object : list){
if (object.getNome().toLowerCase().contains(str.toLowerCase())){
myList.add(object);
}
}
AdapterClass adapterClass = new AdapterClass(myList);
recyclerView.setAdapter(adapterClass);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(SalasActivity.this,databaseError.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
}
Deal.class error E/Androidruntime: FATAL EXCEPTION: main Process: xxx.chat, PID: 11966 com.google.firebase.database.Databaseexception: Can’t Convert Object of type java.lang.String to type .activity.Deal
public class Deal {
private String nome;
private String id;
private String membros;
public Deal() {
}
public Deal(String nome, String id, String membros) {
this.nome = nome;
this.id = id;
this.membros = membros;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMembros() {
return membros;
}
public void setMembros(String membros) {
this.membros = membros;
}
}
thanks it worked out recovered, but my arraylist remains zeroed follows a debug image https://ibb.co/6m4dBqs
– Marc
am having this error now, com.google.firebase.database.Databaseexception: Can’t Convert Object of type java.lang.String to type .activity.Deal I will update the question with the Deal class if you can help me would be grateful
– Marc
@Marc edited my answer with the answers
– Ivan Silva