Reputation: 3
I'm using Firebase and this line of code results in an error.
@Override
public void onCancelled(FirebaseError firebaseError) {
}
The errors are as below,
How to resolve these errors?
My code -
public class FirebaseClient {
Context c;
String DB_URL;
ListView listView;
Firebase firebase;
ArrayList<Dog> dogies= new ArrayList<>();
CustomAdapter customAdapter;
public FirebaseClient(Context c, String DB_URL, ListView listView)
{
this.c= c;
this.DB_URL= DB_URL;
this.listView= listView;
Firebase.setAndroidContext(c);
firebase=new Firebase(DB_URL);
}
public void refreshdata()
{
firebase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
getupdates(dataSnapshot);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
getupdates(dataSnapshot);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
public void getupdates(DataSnapshot dataSnapshot){
dogies.clear();
for(DataSnapshot ds :dataSnapshot.getChildren()){
Dog d= new Dog();
d.setTimestamp(ds.getValue(Dog.class).getTimestamp());
d.setInstituteNotice(ds.getValue(Dog.class).getInstituteNotice());
dogies.add(d);
}
if(dogies.size()>0)
{
customAdapter=new CustomAdapter(c, dogies);
listView.setAdapter((ListAdapter) customAdapter);
} else
{
Toast.makeText(c, "No data", Toast.LENGTH_SHORT).show();
}
}
}
Upvotes: 0
Views: 469
Reputation: 138804
In order to solve this, you need to remove the following method from your code:
@Override
public void onCancelled(FirebaseError firebaseError) {}
You are already overriding public void onCancelled(DatabaseError databaseError)
from its superclass. The code that i adviced you to be removed was used in ealier version of SDK. You need to use the new one.
Upvotes: 0
Reputation: 38289
You are using the legacy Firebase SDK (which has been deprecated for more than a year) and mixing in classes from the new SDK. You should consider migrating to the new SDK. The Upgrade Guide outlines the steps.
In the code you posted, DatabaseError is from the new SDK, not the legacy SDK, so this override is not valid and should be removed:
@Override
public void onCancelled(DatabaseError databaseError) {
}
Upvotes: 1