Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 418 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No setter/getter for Firebase objects

#1
This is my Java class:

public class OnlineMatch{

private FacebookUser firstplayer;
private FacebookUser secondplayer;


public OnlineMatch(){

}


public OnlineMatch(FacebookUser firstplayer, FacebookUser secondplayer) {
this.firstplayer = firstplayer;
this.secondplayer = secondplayer;
}

public FacebookUser getFirstplayer() {
return firstplayer;
}

public void setFirstplayer(FacebookUser firstplayer) {
this.firstplayer = firstplayer;
}

public FacebookUser getSecondplayer() {
return secondplayer;
}

public void setSecondplayer(FacebookUser secondplayer) {
this.secondplayer = secondplayer;
}

}

I can create objects correctly and uploaded to Firebase. The db structure is as follow:
[![Screenshot taken from firebase panel control][1]][1]

[1]:


Then I try to print the values of my OnlineMatch objects (Kotlin code):

val match = dataSnapshot.child("multiplayer").getValue(OnlineMatch::class.java)
if(match!=null){
System.out.println(match)
}

Here I get this output on the Android Studio console:

9548-19548/app.simone W/ClassMapper: No setter/field for -KqV44f4FUxV8ZDuqL4Y found on class app.simone.multiplayer.model.OnlineMatch

08-01 19:14:38.816 19548-19548/app.simone W/ClassMapper: No setter/field for -KqV3sAPXPcYrtr61cDy found on class app.simone.multiplayer.model.OnlineMatch

08-01 19:14:38.816 19548-19548/app.simone W/ClassMapper: No setter/field for -KqV2BGH7Z-Y9RxnPGpt found on class app.simone.multiplayer.model.OnlineMatch
Reply

#2
Your code is asking for *everything* under `multiplayer`, which includes all of the OnlineMatch objects you pushed there previously. You can see from the error message that it's trying to find a setter or field for the push ID `-KqV44f4FUxV8ZDuqL4Y` that it found just under `multiplayer` If you want to get a single OnlineMatch object, you're going to have to dig into the objects in the push IDs under `multiplayer`. So this should give you something:

dataSnapshot.child("multiplayer/-KqV44f4FUxV8ZDuqL4Y").getValue(OnlineMatch::class.java)

In any event, you'll need to have the push ID of your choice, or discover them from the children of the snapshot and build a new snapshot from that child.
Reply

#3
Doug Stevenson, your answer was useful to me.
I created an array of strings where I save the key and then I iterate over the child for each specific key:

override fun onDataChange(dataSnapshot: DataSnapshot) {

// Get Post object and use the values to update the UI
val match = dataSnapshot.children
var keysArray = KeysHandler()
if(match!=null){
// saving keys into an array
for (data in match){
keysArray.addToList(data.key)
}

// saving an OnlineMatch object into another array
repeat(keysArray.list.size){ i->
val onlineMatch = dataSnapshot.child(keysArray.getElement(i)).getValue(OnlineMatch::class.java)!!
requestsUsers.add(onlineMatch)

}

// updating GUI
updateRequests()
}

}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through