0

My recyclerView is loading images and text from the firebase Realtime Database without any problems and I can scroll it fast or slow but when I get to the last item it's crashing. What could be the problem?

Bellow is my logcat

2020-04-09 20:05:05.404 24971-24971/com.example.realestatemw E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.realestatemw, PID: 24971 com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.realestatemw.Agent at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@19.2.1:435) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.2.1:231) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.2.1:79) at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@19.2.1:203) at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:29) at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:15) at com.firebase.ui.common.BaseCachingSnapshotParser.parseSnapshot(BaseCachingSnapshotParser.java:36) at com.firebase.ui.common.BaseObservableSnapshotArray.get(BaseObservableSnapshotArray.java:52) at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:109) at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:149) at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065) at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107) at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279) at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288) at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345) at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361) at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368) at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399) at android.os.Handler.handleCallback(Handler.java:836) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:203) at android.app.ActivityThread.main(ActivityThread.java:6368) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 2020-04-09 20:05:05.458 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0) 2020-04-09 20:05:05.526 1728-1793/? E/MFI-Conn: ( mdfx_conn_conn, 76) mdfx_conn_conn(): the MFI connection fails!! 2020-04-09 20:05:05.526 1728-1793/? E/MFI-Conn: ( mdfx_conn_init_legacy, 363) mdfx_conn_init_legacy(): mdfx_conn_conn() error!! 2020-04-09 20:05:05.526 1728-1793/? E/MFI-RDS: ( rds_mal_conn_init, 819) [RDS][rds_mal_conn_init] mdfx_conn_init_legacy gets NULLLLLLL!!!!! 2020-04-09 20:05:05.709 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0) 2020-04-09 20:05:06.529 1728-1793/? E/MFI-Conn: ( mdfx_conn_conn, 76) mdfx_conn_conn(): the MFI connection fails!! 2020-04-09 20:05:06.529 1728-1793/? E/MFI-Conn: ( mdfx_conn_init_legacy, 363) mdfx_conn_init_legacy(): mdfx_conn_conn() error!! 2020-04-09 20:05:06.529 1728-1793/? E/MFI-RDS: ( rds_mal_conn_init, 819) [RDS][rds_mal_conn_init] mdfx_conn_init_legacy gets NULLLLLLL!!!!! 2020-04-09 20:05:06.680 23860-23898/? E/StreamController: Different sized entryTreeNode vs restored controllers: 10, 5 2020-04-09 20:05:06.969 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0) 2020-04-09 20:05:07.218 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0) 2020-04-09 20:05:07.532 1728-1793/? E/MFI-Conn: ( mdfx_conn_conn, 76) mdfx_conn_conn(): the MFI connection fails!! 2020-04-09 20:05:07.532 1728-1793/? E/MFI-Conn: ( mdfx_conn_init_legacy, 363) mdfx_conn_init_legacy(): mdfx_conn_conn() error!! 2020-04-09 20:05:07.533 1728-1793/? E/MFI-RDS: ( rds_mal_conn_init, 819) [RDS][rds_mal_conn_init] mdfx_conn_init_legacy gets NULLLLLLL!!!!! 2020-04-09 20:05:07.719 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0) 2020-04-09 20:05:07.969 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0) 2020-04-09 20:05:08.219 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0) 2020-04-09 20:05:08.469 1176-1281/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0)

Below is my code

public class HomeFragment extends Fragment {

private RecyclerView recyclerView;


FirebaseRecyclerAdapter<Agent, AgentHolder> firebaseRecyclerAdapter;

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.home_fragment, container, false);
    //1. get a reference to recyclerView
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
    recyclerView.setHasFixedSize(true);

    // 2. set layoutManger
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    ViewCompat.setNestedScrollingEnabled(recyclerView,false);


    FirebaseRecyclerOptions<Agent> options = new FirebaseRecyclerOptions.Builder<Agent>()
            .setQuery(FirebaseDatabase.getInstance().getReference().child("Buy"), Agent.class)
            .build();


    firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Agent, AgentHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull AgentHolder holder, int position, @NonNull Agent model) {
            holder.setCity(model.getCity());
            holder.setTown(model.getTown());
            holder.setImage(holder.mView.getContext(), model.getImage());

        }

        @NonNull
        @Override
        public AgentHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View view1 = LayoutInflater.from(parent.getContext()).inflate(R.layout.individual_row, parent,
                    false);

            return new AgentHolder(view1);
        }
    };


    recyclerView.setAdapter(firebaseRecyclerAdapter);

    return view;

}




@Override
public void onResume() {
    super.onResume();

        firebaseRecyclerAdapter.startListening();
    }

@Override
public void onDestroy() {
    super.onDestroy();
    firebaseRecyclerAdapter.stopListening();
}

}

  • 1
    Please [edit] your question to provide the complete [stack trace from the crash](https://stackoverflow.com/a/23353174). – Mike M. Apr 09 '20 at 00:33
  • First of all, stop ignoring errors. Use `Log.d(TAG, databaseError.getMessage());`. Do you have any message in the logcat? Please also respond with @AlexMamo – Alex Mamo Apr 09 '20 at 10:08
  • @AlexMamo I have no errors in the logcat as I said, the app builds and installs without errors. It only crashes when I scroll to the last item. You can have a look at this https://github.com/Kanyandula/Real_Estate_Mw.git – Ephraim Kanyandula Apr 09 '20 at 18:25
  • If it's crashing, then there is a stack trace somewhere. You just need to find it. Make sure you don't have any filters set on your logcat that might be excluding it. – Mike M. Apr 09 '20 at 18:35
  • Not it. You're looking for a large section of red lines that starts with `FATAL EXCEPTION`. It'll look something like is shown in the image in [this answer](https://stackoverflow.com/a/23353174). Also, please post it as text, rather than as a screenshot. – Mike M. Apr 09 '20 at 19:17
  • @MikeM. I am using androidx libraries on this one but I also have another app that used similar code but I didn't use Androidx and it doesn't crash. I was considering adding an OnScrollListener I don't know if that's a good idea. – Ephraim Kanyandula Apr 09 '20 at 19:26
  • 1
    That doesn't really help us to diagnose your issue. – Mike M. Apr 09 '20 at 19:27
  • 2 ways to look out for errors -- first instead of show only selected application use no filter in log cat or else there would be 2 instance to select from and would be dead so select dead instance at times this happens if your app crashes and starts quickly creating new instance in log cat try either of the methods and see if u can get the error and in love g instead of verbose make it error I mean the log filter – Manoj Mohanty Apr 09 '20 at 19:33

0 Answers0