Я хочу показать мне всех пользователей из базы данных firebase в виде карты, который находится в обзоре переработчика, но в отладчике показывает мне ошибку в строке 60 в UserActivity.
Я поставил скриншот с моей базой данных:
Фрагмент Users:
public class UsersFragment extends Fragment {
private RecyclerView recyclerView;
private UserAdapter userAdapter;
private List<User> mUsers;
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate ( R.layout.fragment_users3, container, false );
recyclerView=view.findViewById (R.id.recycler_view );
recyclerView.setLayoutManager ( new LinearLayoutManager ( getContext () ) );
mUsers=new ArrayList<> ( );
readUsers();
return view;
}
private void readUsers () {
final FirebaseUser firebaseUser= FirebaseAuth.getInstance ().getCurrentUser ();
DatabaseReference referenc= FirebaseDatabase.getInstance ().getReference ("users");
referenc.addValueEventListener ( new ValueEventListener () {
@Override
public void onDataChange (@NonNull DataSnapshot dataSnapshot) {
mUsers.clear ();
for(DataSnapshot snapshot:dataSnapshot.getChildren ()){
User user=snapshot.getValue (User.class);
assert user!=null;
assert firebaseUser!=null;
if(!firebaseUser.getUid ().equals ( user.getUid () )){
mUsers.add ( user );
}
}
userAdapter=new UserAdapter ( getContext (),mUsers );
recyclerView.setAdapter ( userAdapter );
}
@Override
public void onCancelled (@NonNull DatabaseError databaseError) {
}
} );
}
}
UserAdapter.In я использовал класс пользователя:
public class UserAdapter extends RecyclerView.Adapter<UserAdapter.ViewHolder> {
private Context mContext;
private List<User> mUsers;
public UserAdapter(Context mContext,List<User> mUsers){
this.mUsers=mUsers;
this.mContext=mContext;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder (@NonNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from ( mContext ).inflate ( R.layout.users_template ,parent,false);
return new UserAdapter.ViewHolder ( view );
}
@Override
public void onBindViewHolder (@NonNull ViewHolder holder, int position) {
User user=mUsers.get ( position );
holder.username.setText ( user.getFirstName () );
}
@Override
public int getItemCount () {
return mUsers.size ();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView username;
public ViewHolder(View itemView){
super(itemView);
username=itemView.findViewById ( R.id.username1 );
}
}
}
Пользователь, который хранит FirstName:
public class User {
public String firstName;
public String secondName;
public String uid;
public String email;
public User(){
}
public User (String firstName, String secondName, String uid, String email) {
this.firstName = firstName;
this.secondName = secondName;
this.uid=uid;
this.email=email;
}
public User (String firstname, String secondname) {
}
@PropertyName ( "FirsName" )
public String getFirstName () {
return firstName;
}
@PropertyName ("SecondName" )
public String getSecondName () {
return secondName;
}
@PropertyName ( "Uid" )
public String getUid () {
return uid;
}
@PropertyName ( "E-mail" )
public String getEmail () {
return email;
}
@PropertyName ( "FirsName" )
public void setFirstName (String firstName) {
this.firstName = firstName;
}
@PropertyName ( "SecondName" )
public void setSecondName (String secondName) {
this.secondName = secondName;
}
@PropertyName ( "Uid" )
public void setUid (String uid) {
this.uid = uid;
}
@PropertyName ( "E-mail" )
public void setEmail (String email) {
this.email = email;
}
}
Правила для моей базы данных:
{
"rules": {
".read": "true",
".write":"true",
"users":{
"$user_id":{
".read": "auth.uid === $user_id",
".write": "auth.uid === $user_id"
}
}
}
}
В режиме отладки это показывает мне это:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sportsbuddy, PID: 662
com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: secondname
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.addProperty(com.google.firebase:firebase-database@@17.0.0:540)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-database@@17.0.0:471)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-database@@17.0.0:312)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@17.0.0:413)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@17.0.0:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@17.0.0:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@17.0.0:212)
at com.example.sportsbuddy.Fragments.UsersFragment$1.onDataChange(UsersFragment.java:60)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@17.0.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@17.0.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@17.0.0:55)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6986)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Основная ошибка в onDataChange в UsersFragment.
Я ожидаю показать мне всех пользователей, которые у меня есть в базе данных.