Home>

I need to load text and photo from firebase and show them in recycler View. But for some reason, text data cannot always be loaded from the server and the recycler View remains completely empty when the application is restarted (it is loaded 1 time, it is not loaded 2 times, it is loaded 3 times, but not 4 times, etc.). At the end of the method, I check if the data sheet is empty, if so, then I return it to the beginning, this is a stringif (childItemList.size()==0) getChildItemList(category);But in this case, the application gives an error in logcat

The photo won't load at all. It doesn't matter if I get a link to a photo from the server -childItem.setImage(document.getString("image"));or I insert a ready-made link into the recycler View. It's not about the imageView itself, it works fine when I put in it a local photo located in the emulator itself.

Getting data from the server:

private List<ChildItem> getChildItemList(String category) {
    ArrayList childItemList= new ArrayList<>();
    FirebaseFirestore db= FirebaseFirestore.getInstance();
    db.collection(category).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                progressDialog.dismiss();
                for (QueryDocumentSnapshot document : task.getResult()) {
                    Log.d(TAG, document.getId() + "=> " + document.getData());
                    ChildItem childItem= new ChildItem();
                    childItem.setTrackTitle(document.getString("title"));
                    childItem.setAuthor(document.getString("author"));
                    childItem.setDuration(document.getString("duration"));
                    childItem.setImage(document.getString("image"));
                    childItemList.add(childItem);
                }
            } else {
                Log.w(TAG, "Error getting documents.", task.getException());
                Toast.makeText(BrowseTracksActivity.this, task.getException() + "", Toast.LENGTH_SHORT);
            }
        }
    });
    if (childItemList.size()==0) getChildItemList(category); //when I add this line I get an error (below)
    return childItemList;
}

insert data into recycler View:

@Override
    public void onBindViewHolder(@NonNull ChildViewHolder childViewHolder, int position) {
        ChildItem childItem= ChildItemList.get(childViewHolder.getAdapterPosition());
        childViewHolder.trackTitle.setText(childItem.getTrackTitle());
        childViewHolder.author.setText(childItem.getAuthor());
        childViewHolder.duration.setText(childItem.getDuration());
        Glide.with(childViewHolder.itemView.getContext()).load("gs://clearmind1-c3475.appspot.com/Untitled Design.png")
                .into(childViewHolder.photo);
    }

logcat (it just calls the same one until it closes the application):

java.lang.StackOverflowError: stack size 8188KB
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.getState(AbstractQueuedSynchronizer.java:573)
        at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:154)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1291)
        at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:466)at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1067) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1077)
        at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:849)
        at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:336)
        at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:562)
        at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:654)
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.execute(AsyncQueue.java:299)
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.executeAndReportResult(AsyncQueue.java:324)
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.access$500(AsyncQueue.java:205)
        at com.google.firebase.firestore.util.AsyncQueue.enqueue(AsyncQueue.java:428)
        at com.google.firebase.firestore.util.AsyncQueue.enqueue(AsyncQueue.java:439)
        at com.google.firebase.firestore.util.AsyncQueue.enqueueAndForget(AsyncQueue.java:477)
        at com.google.firebase.firestore.core.FirestoreClient.listen(FirestoreClient.java:177)
        at com.google.firebase.firestore.Query.addSnapshotListenerInternal(Query.java:1145)
        at com.google.firebase.firestore.Query.getViaSnapshotListener(Query.java:970)
        at com.google.firebase.firestore.Query.get(Query.java:956)
        at com.google.firebase.firestore.Query.get(Query.java:931)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:109)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)
        at com.example.clearmind1.BrowseTracksActivity.getChildItemList(BrowseTracksActivity.java:129)

Where is your adapter update? Or when "not loaded" the callback goes to else?

woesss2022-02-14 06:39:06

I at first receive all data and only then I send I create the adapter. parentItemAdapter.notifyDataSetChanged(); immediately after the creation of the adapter will not change anything, especially since I am trying to get all the data in the for each loop, so do not return to this code again

Julia2022-02-14 11:57:01