Issue
I'm Trying to remove value from one database and put it in another but the app crashes every time this is executed and i keep getting this error.
code:
firebaseDatabase3= FirebaseDatabase.getInstance().getReference().child("User Ordered").child(PID);
firebaseDatabase3.keepSynced(true);
firebaseDatabase4= FirebaseDatabase.getInstance().getReference().child("Order Ready").child(PID);
firebaseDatabase4.keepSynced(true);
firebaseDatabase5= FirebaseDatabase.getInstance().getReference().child("User Order Ready").child(PID);
firebaseDatabase5.keepSynced(true);
void run1() {
firebaseDatabase4.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.hasChildren()){
firebaseDatabase3.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
firebaseDatabase5.child(ID).setValue(firebaseDatabase3);
run3();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}else{
firebaseDatabase3.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
firebaseDatabase5.child(ID).setValue(firebaseDatabase3);
firebaseDatabase3.removeValue();
run3();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
error
com.google.firebase.database.DatabaseException: Found a conflicting setters with name: setWallpaper (conflicts with setWallpaper defined on android.content.ContextWrapper)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-database@@19.3.0:521)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-database@@19.3.0:329)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:166)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.3.0:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.3.0:675)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:firebase-database@@19.3.0:60)
at com.google.firebase.database.DatabaseReference.setValueInternal(com.google.firebase:firebase-database@@19.3.0:282)
at com.google.firebase.database.DatabaseReference.setValue(com.google.firebase:firebase-database@@19.3.0:159)
at com.example.shopkeeperapp.UserOrders$7$1.onDataChange(UserOrders.java:241)
at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database@@19.3.0:179)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.3.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.3.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.3.0:55)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
Solution
Java objects that you want to write to/read from the Firebase database must follow JavaBean conventions for property naming, and can only contain types that can be serialized to/from JSON.
In your case you're trying to write a android.content.ContextWrapper
object, which does not meet these requirements. This happens from one of these lines:
firebaseDatabase5.child(ID).setValue(firebaseDatabase3);
The firebaseDatabase3
in here is a DatabaseReference
, which does not meet the requirements.
It seems like you want to write the value that you read from one location to another location, in which case you need to get that value from the DataSnapshot
instead of the DatabaseReference
:
firebaseDatabase5.child(ID).setValue(dataSnapshot.getValue());
Answered By - Frank van Puffelen
Answer Checked By - Candace Johnson (JavaFixing Volunteer)