NumberPicker with array from database - java

I wanted to help me develop a numberpicker with a list that I get from firebase, this code now gives me an error and if I delete "setMaxValue and MinValue" it only brings me a single value.
CBSList = new ArrayList<>();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Posts").child(post.getIDPost()).child("CBS");
reference.addValueEventListener( new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
CBSList.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
CBSList.add(snapshot.getKey());
String array[] = new String[CBSList.size()];
for(int j =0;j<CBSList.size();j++){
array[j] = CBSList.get(j);
}
numberPicker.setMaxValue(CBSList.size() - 1);
numberPicker.setMinValue(0);
numberPicker.setDisplayedValues(array);
numberPicker.setWrapSelectorWheel(true);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
} );
error if I leave the two lines of min and max
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ibra.kl, PID: 13463
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at android.widget.NumberPicker.ensureCachedScrollSelectorValue(NumberPicker.java:1900)
at android.widget.NumberPicker.initializeSelectorWheelIndices(NumberPicker.java:1715)
at android.widget.NumberPicker.setMaxValue(NumberPicker.java:1471)
at com.example.ibra.kl.ProductoPostActivity$2.onDataChange(ProdActivity.java:143)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database##16.1.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database##16.1.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database##16.1.0:55)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

You are setting setMaxValue and setMinValue before CBSList is completely filled.
Change your code like this
reference.addValueEventListener( new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
CBSList.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
CBSList.add(snapshot.getKey());
}
String array[] = new String[CBSList.size()];
for(int j =0;j<CBSList.size();j++){
array[j] = CBSList.get(j);
}
if (CBSList.size() > 1) {
numberPicker.setMaxValue(CBSList.size() - 1);
numberPicker.setMinValue(0);
numberPicker.setDisplayedValues(array);
numberPicker.setWrapSelectorWheel(true);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
} );

Related

Unable to start activity ComponentInfo{project} java.lang.IndexOutOfBoundsException: Index:

I have trouble with this error for calling UpdateUI from main activity, MoviesService and LiveMovieServices. I am trying to make movie app
The Error:
05-07 15:30:07.956 3694-3694/com.youssefz.beastmovies.live E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.youssefz.beastmovies.live, PID: 3694
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.youssefz.beastmovies.live/com.example.youssefz.beastmovies.activities.MainActivity}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:411)
at com.example.youssefz.beastmovies.activities.MainActivity.onCreate(MainActivity.java:55)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
The Main Activity
public class MainActivity extends BaseActivity {
#BindView(R.id.activity_main_progressBar)
ProgressBar progressBar;
#BindView(R.id.activity_main_movie_summary)
TextView movieSummary;
#BindView(R.id.activity_main_movieTitle)
TextView movieTitle;
#BindView(R.id.activity_main_movie_vote)
TextView movieVote;
#BindView(R.id.activity_main_moviePicture)
ImageView moviePicture;
#BindView(R.id.activity_main_movieReleaseDate)
TextView movieReleaseDate;
#BindView(R.id.activity_main_left_arrow)
ImageView leftArrow;
#BindView(R.id.activity_main_right_arrow)
ImageView rightArrow;
ArrayList<Movie> movies;
int index;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
movies = new ArrayList<>();
index=0;
bus.post(new MovieServices.SearchMoviesRequest("query"));
UpdateUI(movies.get(0));
}
private void UpdateUI(Movie movie) {
progressBar.setVisibility(View.VISIBLE);
movieTitle.setText(movie.getMovieTitle());
movieSummary.setText(movie.getMovieSummary());
movieReleaseDate.setText(movie.getMovieSummary());
movieVote.setText(Double.toString(movie.getMovieRating()));
Log.i(MainActivity.class.getSimpleName(),movie.getMoviePicture());
Picasso.with(this).load(movie.getMoviePicture())
.fit()
.centerCrop()
.into(moviePicture, new Callback() {
#Override
public void onSuccess() {
progressBar.setVisibility(View.GONE);
}
#Override
public void onError() {
}
});
}
#OnClick(R.id.activity_main_left_arrow)
public void setUpLeftArrow() {
if(index == 0){
Toast.makeText(this,"This is the start of the movies!",Toast.LENGTH_LONG).show();
}else{
index --;
UpdateUI(movies.get(index));
}
}
#OnClick(R.id.activity_main_right_arrow)
public void setUpRightArrow() {
if(index == movies.size()-1){
Toast.makeText(this,"This is the end of the movies!",Toast.LENGTH_LONG).show();
}else{
index ++;
UpdateUI(movies.get(index));
}
}
#Subscribe
public void getMovieMessage(MovieServices.SearchMoviesResponse response) {
movies.clear();
movies = response.movies;
}
}
The MovieServices
public class MovieServices {
private MovieServices(){
}
public static class SearchMoviesRequest{
public String query;
public SearchMoviesRequest (String query){
this.query = query;
}
}
public static class SearchMoviesResponse{
public ArrayList<Movie> movies;
}
}
The LiveMovieService:
public class LiveMovieService extends BaseLiveServices {
public LiveMovieService(BeastMoviesApplication application) {
super(application);
}
#Subscribe
public void getMovieMessage(MovieServices.SearchMoviesRequest request){
MovieServices.SearchMoviesResponse response = new MovieServices.SearchMoviesResponse();
response.movies = new ArrayList<>();
for(int i=0;i<4;i++){
Movie movie = new Movie ("Joe's android movie" + i+ "!", "The is a movie where Joe has Android Dreams" + i, BeastMoviesApplication.BESE_PICTURE_URL+"/wSJPjqp2AZWQ6REaqkMuXsCIs64.jpg","10/3/2016",5.0);
response.movies.add(movie);
}
bus.post(response);
}
}
movies = new ArrayList<>();
Here, you assign an empty ArrayList to movies.
Then, three Java statements later, you call movies.get(0). Since movies is empty, you cannot get() an object out of movies.
You are trying to get the first item of your empty ArrayList without waiting for response from webservice.
You should wait for the response from your web service to fill your ArrayList. After that you can call this method(if the list is not empty).
UpdateUI(movies.get(0));
movies is empty, so you can not use movies.get(0)

Get last node in Firebase database

I want to access location details from the last added node in Firebase database. You can see on the image below. Its giving error. Please tell me where to correct.
Here is my code
DatabaseReference dbReference = FirebaseDatabase.getInstance().getReference();
Query lastQuery = dbReference.child("User").child("Location").orderByKey().limitToLast(1);
lastQuery.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
LatLng prevloc = new LatLng(
dataSnapshot.child("latitude").getValue(Double.class),
dataSnapshot.child("longitude").getValue(Double.class));
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
Here is error
03-21 18:32:10.328 1093-1093/com.jkweblander.mapviewex E/dalvikvm: Could not find class 'dalvik.system.DelegateLastClassLoader', referenced from method ab.b
03-21 18:32:14.068 1093-1093/com.jkweblander.mapviewex E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jkweblander.mapviewex, PID: 1093
java.lang.NullPointerException
at com.jkweblander.mapviewex.MapsActivity$2.onDataChange(MapsActivity.java:240)
at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database##16.1.0:183)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database##16.1.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database##16.1.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database##16.1.0:55)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
To solve this, please use the following code:
DatabaseReference dbReference = FirebaseDatabase.getInstance().getReference();
Query lastQuery = dbReference.child("User").child("Location").orderByKey().limitToLast(1);
lastQuery.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
double lat = ds.child("latitude").getValue(Double.class);
double lng = ds.child("longitude").getValue(Double.class);
LatLng prevloc = new LatLng(lat, lng);
Log.d(TAG, lat + ", " + lng);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {}
});
See, I have used the getChildren() method to iterate through the DataSnapshot object. The result in your logcat will be all latitudes and longitudes of your items within Location node. So even if there is a single obejct in your DataSnapshot object you should iterate in order to get it.

Firebase onDataChange - null object reference

I'd like to ask if someone can fix this for me.. cuz i've been searching and trying to fix it myself but .. nope..
here's my logcat error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.mk.transportrider, PID: 23152
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.app.mk.transportrider.Model.Rider.getName()' on a null object reference
at com.app.mk.transportrider.Home$5$1.onDataChange(Home.java:364)
at com.google.firebase.database.zzp.onDataChange(Unknown Source:7)
at com.google.android.gms.internal.firebase_database.zzfc.zza(Unknown Source:13)
at com.google.android.gms.internal.firebase_database.zzgx.zzdr(Unknown Source:2)
at com.google.android.gms.internal.firebase_database.zzhd.run(Unknown Source:71)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
and here is my "code":
DatabaseReference driverLocation = FirebaseDatabase.getInstance().getReference(Common.driver_tbl);
GeoFire gf = new GeoFire(driverLocation);
GeoQuery geoQuery = gf.queryAtLocation(new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()), distance);
geoQuery.removeAllListeners();
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
#Override
public void onKeyEntered(String key, final GeoLocation location) {
FirebaseDatabase.getInstance().getReference(Common.user_driver_tbl)
.child(key)
.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Same model *users* & *driver*
// using the ssame model ---
Rider rider = dataSnapshot.getValue(Rider.class);
mMap.addMarker(new MarkerOptions()
.position(new LatLng(location.latitude, location.longitude))
.flat(true)
.title(rider.getName())
.snippet("Phone: " + rider.getPhone())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.car)));
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
(Home.java:364) is the line code .title(rider.getName())
Ough.. and if there is something else i could provide you more, that you need i'll post it as soon as i can.
And please understand.. i'm kinda trying to get these things by myself but, no can do .. i just got stuck even if it is that simple :( ..
Thank you.
Adding "if(dataSnapshot.exists())" before this line of code.. started working :)
Rider rider = dataSnapshot.getValue(Rider.class);
mMap.addMarker(new MarkerOptions()
.position(new LatLng(location.latitude, location.longitude))
.flat(true)
.title(rider.getName())
.snippet("Phone: " + rider.getPhone())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.car)));

Firebase Auth firebase user get UID returing null.

This is my Logcat, im getting an error in this Post Activity.class.
In my Firebase Database, it looks like this and i hope you understand my questions.[enter image description here][1]
Process: com.databaseblog.winter.databasereferenceblogexample, PID: 32581
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.databaseblog.winter
.databasereferenceblogexample/com.databaseb
log.winter.databasereferenceblogexample.PostActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null
object reference
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2570)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2636)
at android.app.ActivityThread.access$1000(ActivityThread.java:180)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5811)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.
ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:768)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String com.google.firebase
.auth.FirebaseUser.getUid()' on a null object reference
at
com.databaseblog.winter.databasereferenceblogexample
.PostActivity.onCreate(PostActivity.java:75)
at android.app.Activity.performCreate(Activity.java:6342)
at android.app.Instrumentation
.callActivityOnCreate(Instrumentation.java:1113)
This is my PostActivity
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
final Uri downloadUrl = taskSnapshot.getDownloadUrl();
final DatabaseReference newPost = mDatabase.push();
mDatabaseUser.addValueEventListener(new ValueEventListener()
{
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
newPost.child("uid").setValue(mCurrentUser.getUid());
newPost.child("title").setValue(title_val);
newPost.child("desc").setValue(desc_val);
newPost.child("image").setValue(downloadUrl.toString());
newPost.child("timestamp").setValue(ServerValue.TIMESTAMP);
newPost.child("username").setValue(dataSnapshot.child("name")
.getValue()).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task)
{if (task.isSuccessful()){
Intent postIntent = new Intent(PostActivity.this,MainActivity.class);
postIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(postIntent);
finish();
}
}
});
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
mProgress.dismiss();
Error comes from this LINES
mAuth = FirebaseAuth.getInstance();
mDatabase =
FirebaseDatabase.getInstance().getReference().child("Mizo_Blog");
mStorage = FirebaseStorage.getInstance().getReference();
mDatabaseUser =
FirebaseDatabase.getInstance().getReference()
.child("Users").child(mCurrentUser.getUid());
And i attached my Firebase Database Image also. since this Auto Text checker is telling me most of this text are code.. im just typing stupid things.. i really could use some help here. [1]: https://i.stack.imgur.com/3Lhtc.jpg

How can I populate a Spinner with Firebase data?

I've trawled through online articles on threads on SO to try and figure out how I can do this, but haven't come any closer.
This thread (How to get a String List from Firebase to fill a Spinner) seems like it could be beneficial, however I'm unsure how to implement it for my own scenario.
I want the property addresses to be present in the spinner.
Apologies if the question seems vague, quite hard to explain.
MaintenanceActivity
public class MaintenanceActivity extends AppCompatActivity {
EditText editTextTitle;
EditText editTextDesc;
Spinner spinnerPrimary;
Spinner spinnerSecondary;
Spinner spinnerProperty;
Button buttonSubmit;
DatabaseReference databaseMaintenance;
ListView listViewIssues;
List<Maintenance> maintenanceList;
fDatabaseRoot.child("propertyAddress").addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Is better to use a List, because you don't know the size
// of the iterator returned by dataSnapshot.getChildren() to
// initialize the array
final List<String> propertyAddress = new ArrayList<String>();
for (DataSnapshot addressSnapshot: dataSnapshot.getChildren()) {
String propertyAddress = addressSnapshot.child("propertyAddress").getValue(String.class);
propertyAddress.add(propertyAddress);
}
Spinner spinnerProperty = (Spinner) findViewById(R.id.spinnerProperty);
ArrayAdapter<String> addressAdapter = new ArrayAdapter<String>(MaintenanceActivity.this, android.R.layout.simple_spinner_item, areas);
addressAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerProperty.setAdapter(addressAdapter);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
activity_maintenance
<Spinner
android:id="#+id/spinnerProperty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/fuel" />
Firebase Database
Firebase
Error
Getting several errors with this answer. I have had these errors previously, not sure how to solve them.
Errors
LogCat Error
03-01 17:19:53.402 28517-28517/com.example.***.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.***.myapplication, PID: 28517
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:445)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:493)
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:994)
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:990)
at android.widget.Spinner.measureContentWidth(Spinner.java:856)
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1225)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1251)
at android.widget.Spinner.performClick(Spinner.java:780)
at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:442)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
03-01 17:19:53.403 28517-28517/com.example.***.myapplication E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:445)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:493)
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:994)
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:990)
at android.widget.Spinner.measureContentWidth(Spinner.java:856)
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1225)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1251)
at android.widget.Spinner.performClick(Spinner.java:780)
at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:442)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
There so much I can help you with, but you'll need to configure the database and firebase, see docs.
After that in your activity:
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference fDatabaseRoot = database.getReference();
fDatabaseRoot.child("properties").addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Is better to use a List, because you don't know the size
// of the iterator returned by dataSnapshot.getChildren() to
// initialize the array
final List<String> propertyAddressList = new ArrayList<String>();
for (DataSnapshot addressSnapshot: dataSnapshot.getChildren()) {
String propertyAddress = addressSnapshot.child("propertyAddress").getValue(String.class);
if (propertyAddress!=null){
propertyAddressList.add(propertyAddress);
}
}
Spinner spinnerProperty = (Spinner) findViewById(R.id.maintenanceProperty);
ArrayAdapter<String> addressAdapter = new ArrayAdapter<String>(MaintenanceActivity.this, android.R.layout.simple_spinner_item, propertyAddressList);
addressAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerProperty.setAdapter(addressAdapter);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
You had added a listener for the propertyAddress, but when the datasnapshot returned you were probing for propertyAddress again, which wouldn't work because the listener would return the property address already. The way I wrote above it will return all keys in your database, in each key you have a propertyAddress that can be retrieved. Give it a try.

Resources