Ich habe gesucht, aber konnte nicht die Antwort bekommen. Ich habe meine Firebase Datenbank. Ich lade alle Daten ab und zeige sie in der Listenansicht an. Dazu verwende ich addValueEventListener aber die Sache ist OnDataChange nicht ausgeführt und das Ergebnis ist null ArrayList, die NullPointer Fehler gibt. Wenn mir jemand helfen kann, wäre ich dankbar. Danke im Voraus! OnDataChange nie ausgeführt, während retreiving Daten
RecipesDisplay:
ListView list;
DatabaseReference mDatabaseRef;
FirebaseDatabase mRef;
String[]t;
int[] im;
ArrayList<Recipe> recipes = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_recipes_display);
list = (ListView) findViewById(R.id.listview);
final FirebaseDatabase database = FirebaseDatabase.getInstance();
mDatabaseRef = database.getReference("https://fir-practice-
41da3.firebaseio.com/New Recipes/");
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
recipes = new ArrayList<>();
for (DataSnapshot msgSnapshot : dataSnapshot.getChildren()) {
Recipe msg = msgSnapshot.getValue(Recipe.class);
recipes.add(msg);
Toast.makeText(getApplicationContext(),"LD
!!!",Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled (DatabaseError databaseError){
Toast.makeText(getApplicationContext(),"FAILD
!!!",Toast.LENGTH_LONG).show();
}
});
for (int i =0;i<recipes.size();i++){
t[i] = recipes.get(i).getTitle();
im[i] = R.drawable.breakfast_1;
}
CustomAdapterCategory adapter = new CustomAdapterCategory(this,t,im);
list.setAdapter(adapter);
}
}
Build.Gradle (app):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'