I'm newly working with FirebaseDatabase in android studio. I'm giving you a part of my code that doesn't work but supposed to do.
btnGetInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str = 33 + "";
/*
database = FirebaseDatabase.getInstance();
reference = database.getReferenceFromUrl("https://test-4e354.firebaseio.com/");
*/
database.getReference(str).addValueEventListener(
new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Toast.makeText(MainActivity.this, "test",Toast.LENGTH_LONG)
.show();
Boxer boxer = dataSnapshot.getValue(Boxer.class);
if(boxer == null) return;
txtName.setText(boxer.getName());
txtPPower.setText(boxer.getPaunchPower());
txtPSpeed.setText(boxer.getPaunchSpeed());
txtStamina.setText(boxer.getStamina());
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
}
);
}
});
The program doesn't even enter in the line
database.getReference(str).addValueEventListener()
When i click on the Button
btnGetInfo
, my app get crushed.
why?
I can't find any problem.
Can you help me please?
Here is the database structure:
And this is the 'Logcat' :
2020-06-24 19:38:47.534 25686-25686/com.example.firstfirebaseproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.firstfirebaseproject, PID: 25686
com.google.firebase.database.DatabaseException: Class com.example.firstfirebaseproject.Boxer does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.4:557)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.4:550)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.4:420)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.4:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@16.0.4:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@16.0.4:212)
at com.example.firstfirebaseproject.MainActivity$1$1.onDataChange(MainActivity.java:71)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@16.0.4:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@16.0.4:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@16.0.4:55)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
I don't know what does it means.
And this is the Boxer class:
public class Boxer {
private String name, paunchPower, paunchSpeed, stamina;
public Boxer(String name, String paunchPower, String paunchSpeed, String stamina) {
this.name = name;
this.paunchPower = paunchPower;
this.paunchSpeed = paunchSpeed;
this.stamina = stamina;
}
Thanks <3