I am getting a null pointer exception (have tested 1 instead of i here)
This is the method
public String getLat(int i) {
fillDriverList();
arrayLat.get(i);
return"0.000";
}
This is where it is called from in separate activity
AdminActivity appState = new AdminActivity();
latString = appState.getLat(i);
Here is the fill method, which is printing out the drivers names so appears to be filling the list, but then is null for some reason in my getLat method??
public void fillDriverList() {
//Creating firebase object
Firebase ref = new Firebase(Config.FIREBASE_URL);
//adding a value event listener so if data in database changes it does in textview also not needed at the minute
ref.child("Driver").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
arrayLat = new ArrayList<String>();
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Driver d = postSnapshot.getValue(Driver.class);
System.out.println("data snapshot Drivers name is -------------------> "+d.getName());
arrayLat.add(Double.toString(d.getLat()));
}
}
/************had to implement this method****************/
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
}
NOTE When I pass it like this
intent.putStringArrayListExtra("arrayLat", arrayLat);
there is no problem using it in the other actvity like this
arrayLat = I.getStringArrayListExtra("arrayLat");
Although the values I use then in the next activity are stored values and do not update when my information(latitude) in firebase changes.
Thanks