Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – How can I solve this Android Studio Firebase problem?

Posted on November 11, 2022 By

Solution 1 :

Data is loaded from Firebase asynchronously. Right now your Log.i("asdfads",(bilgiler.get("asdf"))); is run before bilgiler.put("asdf", document.getData().toString()) runs, which explains why you don’t see the value from the database.

Any code that needs data from the database, needs to be inside the onComplete method, or be called from there. So:

db.collection("tarihBilgi")
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult())) {
                    bilgiler.put("asdf", document.getData().toString());
                    Log.i("asdfads",(bilgiler.get("asdf")));
                }
            } else {
                Log.w("TAG", "Error getting documents.", task.getException());
            }
        }
    });

Also see:

  • How to check a certain data already exists in firestore or not
  • User login in Firebase
  • How to return a DocumentSnapShot as a result of a method?
  • Wait until Firestore data is retrieved to launch an activity
  • Problems with Firestore connections executing threads

Problem :

This question already has answers here:

Problems with Firestore connections executing threads

(3 answers)
Closed 2 years ago.

I am trying to get data from Firebase to bilgiler variable. But I get error all the time. How can I solve this?

Map<String, String> bilgiler = new HashMap<>();

db.collection("tarihBilgi")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {
                            for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult())) {
                                //Log.d("TAG", document.getId() + " => " + document.getData());
                                bilgiler.put("asdf", document.getData().toString());
                            }
                        } else {
                            Log.w("TAG", "Error getting documents.", task.getException());
                        }
                    }
                });
        Log.i("asdfads",(bilgiler.get("asdf")));
READ  [FIXED] EXPO Native app that works fails when running in android
Powered by Inline Related Posts
Android Tags:android, firebase, google-cloud-firestore, java

Post navigation

Previous Post: [FIXED] java – How to handle large amount of animated vector drawables?
Next Post: [FIXED] c# – Call a self hosted web api from an Android app through a DDNS

Related Posts

[FIXED] android – Navigate to a fragment from another graph without it being the start destination Android
[FIXED] java – Show app icon on contact details in Android Android
[FIXED] How to sum json value after sorted in java android? Android
[FIXED] Android Studio slow start on Ubuntu 19.10 Android
[FIXED] javascript – Receiving “Function returned undefined, expected Promise or value” message in logs explorer Android
[FIXED] firebase – create user with email and password and put data in database Fire base Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme