I have sent data to my firebase database underneath the key "Bench" and i am trying to retrieve the data onto android studio by creating a arrayadapter :
public class ScoreInfoAdapter extends ArrayAdapter<ScoreProfile> {
private Activity context;
private List<ScoreProfile> scoreList;
public ScoreInfoAdapter(Activity context, List<ScoreProfile>scoreList){
super(context,R.layout.list_view,scoreList);
this.context =context;
this.scoreList = scoreList;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listview = inflater.inflate(R.layout.list_view, null, true);
TextView Scorename = (TextView)listview.findViewById(R.id.Name_bench);
TextView Scorelevel = (TextView)listview.findViewById(R.id.Score_of_bench);
ScoreProfile scoreProfile = scoreList.get(position);
Scorename.setText(scoreProfile.getUserName());
Scorelevel.setText(scoreProfile.getUserScore());
return listview;
}
}
I have created a layout resource file with a list view with two textviews. "Name", "Score". I have created a class with an xml layout to display the information with a list view and on the class for this activity i have used this code to retrieve data:
private FirebaseAuth firebaseAuth;
private ListView listView;
DatabaseReference databaseReference;
private FirebaseDatabase firebaseDatabase;
List<ScoreProfile> scoreList;
@Override
protected void onStart() {
super.onStart();
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot scoreSnapshot : dataSnapshot.getChildren()){
ScoreProfile scoreProfile = scoreSnapshot.getValue(ScoreProfile.class);
scoreList.add(scoreProfile);
}
ScoreInfoAdapter scoreInfoAdapter = new ScoreInfoAdapter(RankT.this, scoreList);
listView.setAdapter(scoreInfoAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rank_t);
Toolbar toolbar = findViewById(R.id.toolbarMain);
toolbar.setTitle("GymTastic Rank Table");
listView = findViewById(R.id.listview);
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("Bench");
scoreList = new ArrayList<>();
firebaseAuth = FirebaseAuth.getInstance();
However, when i run the app i get this error :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gymtastic, PID: 14505
com.google.firebase.database.DatabaseException: Class com.example.gymtastic.ScoreProfile 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@@19.2.0:569)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@19.2.0:562)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@19.2.0:432)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.2.0:231)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.2.0:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@19.2.0:203)
at com.example.gymtastic.RankT$1.onDataChange(RankT.java:52)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.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)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
What can I do to prevent this error and successfully present data pulled from the Database.