0

I wrote some code to get data from Firebase, but it shows some errors. I will explain the errors below and attach a picture.

enter image description here

First error when I put the mouse on it, message show: 'onStart()' in 'com.abdullrahman.eng.myapp.FriendsFragment' clashes with 'onStart()' in 'android.app.Fragment'; attempting to assign weaker access privileges ('protected'); was 'public'

Second error when I put the mouse on it, message show: Method does not override method from its superclass

Can anyone solve these problems and help me?

The code:

@Override
protected void onStart() {
    super.onStart();

    FirebaseRecyclerAdapter<Friends, FriendsViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Friends, FriendsViewHolder>(

            Friends.class,
            R.layout.users_single_layout,
            FriendsViewHolder.class,
            mUsersDatabase

    ) {
        @Override
        protected void populateViewHolder(FriendsViewHolder friendsViewHolder, Friends friends, int position) {

            friendsViewHolder.setDisplayName(friends.getName());
            friendsViewHolder.setUserStatus(friends.getStatus());
            friendsViewHolder.setUserImage(friends.getThumb_image(), mMainView.getContext());

            final String user_id = getRef(position).getKey();

            friendsViewHolder.mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Intent profileIntent = new Intent(getActivity(), UserProfile.class);
                    profileIntent.putExtra("user_id", user_id);
                    startActivity(profileIntent);

                }
            });
        }
    };

    mUsersList.setAdapter(firebaseRecyclerAdapter);

}
rgettman
  • 176,041
  • 30
  • 275
  • 357

2 Answers2

1

Errors do say a lot about the problem you have.

The first error is caused by protected access modifier on the onStart() method, while it should be public. It should be

@Override
public void onStart() {
    super.onStart();
    // rest of the code
}

instead of

@Override
protected void onStart() {
    super.onStart();
    // rest of the code
}

You can find some more information about the error reason in docs available on Oracle site.

The second problem is related to the definition of FirebaseRecyclerAdapter. Looks like there is no method like

protected void populateViewHolder(FriendsViewHolder friendsViewHolder, Friends friends, int position).

I'd suggest checking docs/sources of this class to get info about how the override method should look for the version of Firebase you are using in your project.

Also, as I can see you are using IntelliJ IDEA or some similar IDE, so you can use built-in feature to implement/override the correct method.

Stanislau Buzunko
  • 1,630
  • 1
  • 15
  • 27
Kamil
  • 2,712
  • 32
  • 39
  • Can you edit the code and correct the problems , Because i can't fix problems. –  Mar 15 '18 at 23:18
  • I've updated it, but that's all I can do without information about version of the Firebase - I can't tell what should be the exact method you want to override. – Kamil Mar 16 '18 at 00:11
  • The first problem solved, But second problem not solved, This is my gradle implementations firebase: implementation 'com.google.firebase:firebase-auth:11.8.0' implementation 'com.firebaseui:firebase-ui-database:3.1.0' implementation 'com.google.firebase:firebase-database:11.8.0' implementation 'com.google.firebase:firebase-storage:11.8.0' implementation 'com.google.firebase:firebase-messaging:11.8.0' –  Mar 16 '18 at 13:00
  • Looks like an implementation has changed. I supose, that what you need in ``protected void onBindViewHolder(ChatHolder holder, int position, Chat model)`` method. You can check Firevase README.md file https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md and this post on Stackoverflow https://stackoverflow.com/questions/46859983/i-cant-find-populateviewholder-method-in-firebaserecycleradapter-class – Kamil Mar 16 '18 at 20:18
0

Change your protected modifier to public and it'll go away.

In Java, the overriding method can have the same or weaker access compared to the parent method... Here the parent class declares the method as public so you have no other choice but to override it with a public access modifier as it's the weakest access possible.

Kushan
  • 5,855
  • 3
  • 31
  • 45