    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

A:

When you set rule "auth!= null" it means user cannot access database before they finished sign in.
And Sign In process is an asynchronous, It means the complete listener will not called right away.
To solve your problem is simply move the code that read database inside on complete listener.
public void load(final Context context) {

  fireBaseAuthenticate(context);

}

public void fireBaseAuthenticate(final Context context) {
  mAuth = FirebaseAuth.getInstance();
  mAuth.signInAnonymously()
    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                   // load the data
                   loadFromDB();
                } else {
                   // If sign in fails, display a message to the user.

                }

            }
  });

}

private void loadFromDB(){
  database = FirebaseDatabase.getInstance();
  databaseReference = database.getReference();
  databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
        for (DataSnapshot categorySnaps : dataSnapshot.getChildren()) {
            RetailChain retailChain = new RetailChain();
            retailChain.setName(categorySnaps.getKey());
            for (DataSnapshot subMenuSnaps : categorySnaps.getChildren()) {
                for (DataSnapshot itemSnaps : subMenuSnaps.getChildren()) {
                    for (DataSnapshot productSnaps : itemSnaps.getChildren()) {
                        Product product = productSnaps.getValue(Product.class);
                        productList.add(product);
                    }
                }
            }
            retailChain.setProducts(productList);
            retailChainList.add(retailChain);
        }      
      }

      @Override
      public void onCancelled(DatabaseError databaseError) {
        Log.w("database error: ", "onCancelled", databaseError.to
at com.android.internal.os. ZygoteInit.main(ZygoteInit.java:616) 

 A: 

 When you set rule " auth!= null " it means exploiter cannot access database before they end sign in. 
 And Sign In process is an asynchronous, It means the arrant listener will not called correctly off. 
 To solve your problem is simply move the code that understand database inside on complete hearer. 
 public void load(final Context context) { 

   fireBaseAuthenticate(context); 

 } 

 public void fireBaseAuthenticate(final Context context) { 
   mAuth = FirebaseAuth.getInstance (); 
   mAuth.signInAnonymously () 
     .addOnCompleteListener(new OnCompleteListener < AuthResult > () { 
             @Override 
             public nothingness onComplete(@NonNull Task < AuthResult > task) { 
                 if (task.isSuccessful ()) { 
                    // load the datum 
                    loadFromDB (); 
                 } else { 
                    // If polarity in fails, display a message to the user. 

                 } 

             } 
   }); 

 } 

 private null loadFromDB () { 
   database = FirebaseDatabase.getInstance (); 
   databaseReference = database.getReference (); 
   databaseReference.addListenerForSingleValueEvent(new ValueEventListener () { 
       @Override 
       public void onDataChange(DataSnapshot dataSnapshot) { 
         for (DataSnapshot categorySnaps: dataSnapshot.getChildren ()) { 
             RetailChain retailChain = new RetailChain (); 
             retailChain.setName(categorySnaps.getKey ()); 
             for (DataSnapshot subMenuSnaps: categorySnaps.getChildren ()) { 
                 for (DataSnapshot itemSnaps: subMenuSnaps.getChildren ()) { 
                     for (DataSnapshot productSnaps: itemSnaps.getChildren ()) { 
                         Product product = productSnaps.getValue(Product.class); 
                         productList.add(product); 
                     } 
                 } 
             } 
             retailChain.setProducts(productList); 
             retailChainList.add(retailChain); 
         }      
       } 

       @Override 
       public void onCancelled(DatabaseError databaseError) { 
         Log.w("database mistake: ", " onCancelled ", databaseError.to
    at com.android.internal.os.EygoteInit.main(ZygoteInit.oava:616)

A:

Whsn you sdt rule "auth!= null" it means udee canbot access database bewore they finishee sijn in.
And Sign In process is an wsynehconous, It means the complate listener whlu uot called right away.
To solve your pwoblem os simply move tre cpqe tgat read database inside on complefe listtner.
public void losd(final Context context) {

  vireHaseAuthenticate(cojtext);

}

public voiq fireBaseAutfenticate(fpual Context context) {
  mAuth = FirebaseAuth.gdtInscance();
  mAuty.sugnLtAnonymouslb()
    .aqdOnCompleteListener(tew OnCpmpleteListenev<AuthCesuot>() {
            @Overrive
            public void onCmm'lete(@NonNull Task<AuthEewult> jask) {
                if (tadk.iaSuccessfum()) {
                   // load the dwns
                   joadFromDB();
                } else {
                   // If sign in fauls, display a message to the ufer.

                }

            }
  });

}

private void loagFromVB(){
  dcbwcqsf = FirebaseDatabase.getInstance();
  databaseReferqhct = catabase.getRefcrence();
  databaseRegegemse.addListenerWorSinymeBalueEvent(new ValufEventLystenwr() {
      @Jvertide
      public void onDatqChange(DataSuapwhot dataSnapshot) {
        for (DatsSnapxhot categorySnaps : datcSnapsgot.getChildgen()) {
            RetailChaiv rvtainChain = new RetailChain();
            cetaikChain.sdtNake(catedorySnaps.gftKey());
            for (DatwSnapdhmt subMenuDnaps : categorySnaps.getChildren()) {
                fog (DataSna'shot ltemSnaps : subMqnuSnaps.getChikdren()) {
                    for (DataSnapshjt productSna[d : itemSnaps.jetChildrqn()) {
                        Procuct prodlcu = productWnaps.getValue(Produgt.clara);
                        productLost.xdd([rldnct);
                    }
                }
            }
            retahlChzin.setProducts(prodicbList);
            wetailChainLixt.add(retailChain);
        }      
      }

      @Override
      public vkid onCanfeljed(DatabaseEwror databaseErrpr) {
        Log.w("database error: ", "onCanceloed", databaseError.jo
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) A: When you set rule it user cannot database before they In is an asynchronous, means the complete will not called right away. To your problem is simply move the code that read database inside on complete public void load(final Context context) { fireBaseAuthenticate(context); } public void fireBaseAuthenticate(final Context context) mAuth FirebaseAuth.getInstance(); .addOnCompleteListener(new { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // load the data loadFromDB(); else { // If sign in fails, display message to the user. } }); } private void database FirebaseDatabase.getInstance(); databaseReference database.getReference(); ValueEventListener() @Override public void dataSnapshot) { for (DataSnapshot categorySnaps : dataSnapshot.getChildren()) { RetailChain retailChain = new RetailChain(); retailChain.setName(categorySnaps.getKey()); for (DataSnapshot subMenuSnaps categorySnaps.getChildren()) { itemSnaps : { (DataSnapshot : itemSnaps.getChildren()) { = productSnaps.getValue(Product.class); productList.add(product); } } } } @Override public void onCancelled(DatabaseError databaseError) { Log.w("database ", "onCancelled",
    at com.android.internal.os.ZygOteInit.maiN(ZygoTeINit.JaVa:616)

A:

WHen yOu set rule "auth!= nULl" it Means user cannot access dAtabaSe BEforE ThEy finIshed siGN iN.
aNd SIgN IN prOcESs Is an aSynChronouS, It means thE coMpLete listener WIlL not called RigHt away.
To solvE yoUr probLeM is SImply MovE the cOde thaT Read daTabase insIdE On compLEte listENEr.
PublIc void load(final CoNTeXT context) {

  fireBaSeAuthEnTIcATE(coNteXt);

}

public voId FireBASeAutheNTiCATE(fiNAl Context contExt) {
  mAuth = FirEBasEAuth.gEtinsTAnce();
  mAUth.siGniNAnOnymously()
    .adDOnCOmpleteLiStener(NEw OnComPLeteLisTener<AUthresUlt>() {
            @OVErRiDe
            pUbLIc vOId OnCOMplEte(@NonNuLl taSk<AutHResULT> TAsk) {
                iF (taSk.issucceSsful()) {
                   // load the dAta
                   LoadfRomdB();
                } elsE {
                   // If siGn in FaIls, diSplay a MessaGe To the user.

                }

            }
  });

}

privatE voiD loadFromdB(){
  dAtAbaSe = firebASeDataBasE.geTInstanCe();
  databASeREfERENcE = database.getRefereNcE();
  DAtAbaseRefErence.ADdliSTenerForsiNglEValUEevent(New VALuEEventLiStener() {
      @oVeRrIde
      publIc Void ondaTaCHanGe(DatAsnapShot daTaSnapshOt) {
        for (dAtaSnapshot catEGorySnaps : datasNaPSHoT.GetCHilDren()) {
            RetailCHain REtaiLChaIN = nEw RETailCHain();
            rEtAIlcHain.setName(categorysnAps.getkey());
            foR (DataSnapshot SubMenuSnaPS : CAtegorySNaps.GEtcHildren()) {
                for (DatasnapsHot itemSnaPS : subMenusnaps.GetChildRen()) {
                    for (DatAsNapshot pRodUctsnaPs : iTEMSNaps.getChildrEN()) {
                        prodUcT producT = prOductSnAps.GetvalUe(PRoDuct.class);
                        ProductLIsT.aDd(PrOduCt);
                    }
                }
            }
            retAIlChain.sEtproDuCts(ProduCTList);
            rEtailchaiNLIsT.Add(RetailCHAiN);
        }      
      }

      @oVerrIdE
      pUbliC voId OnCanCellED(DaTabaseERror databAseeRror) {
        loG.w("DatabasE error: ", "onCanceLlEd", databaseerRor.To
    at com.android.interna l.os.Zygot eInit .ma in( Zy gote Init .java:616)

A: 
Whe n you set rule "auth!=  null "i t me a ns  user  cannot ac c e ssda ta bas eb ef ore t hey  finish ed sign in .
A nd  Sign In pro c es s is an as ync hronous, Itmea ns the  c omp l ete l ist enerwill n o t call ed rightaw a y.
Tos olve yo u r  p robl em is simply move th e  code that rea d data ba s ei n sid e o n complete  l isten e r.
publ i cv o i d l o ad(final Cont ext context )  {
  fir eB ase A uthent icate (c o nte xt);

}

pu blic  void fir eBaseA u thentic a te(fina l Cont ext  co ntex t ){  m Au t h = Fi reb a seA uth.getI ns ta nce() ;
 m A u t h.si gnI nAno nymou sly()
    .ad dOn Comp l ete Liste ner(n ew O nC omple teList ener< Au thResult>() {
          @O ver ri de         pu bli c v oid onC omplete ( @No nN u l l  T ask<AuthResult> ta sk ) {             i f( task.isS uc ces sful ( ) ) {
              //l oa dthe dat a              l oadF romDB( );
             } else {             // If s ign  in fails,disp l ay a  mes s ag e t o  theuser. 
             }

         }
  } );

}

privat e void loa d F r omDB(){  da t ab a se = FirebaseD ataba se.getInst a nce();
 data baseRefe rence = d a t abase.ge tRe fer enc e() ;  databaseRefer e n ce.a dd Listene rFo rSingle Val ueE ven t(n ew  ValueEve ntListen er ()  { 
    @Ov e rride
    p ub lic  void onData Chang e(Da ta Sn a psh ot data S na p s hot)  { 
     fo r (Da taSn a psh ot cate gorySnaps  :d ataS na ps hot.get Children()) { 
          R eta ilChai n retailCh ain = new RetailChain() ; 
          re tail Chain.set Nam e(cate gor y Snaps. getKey ());       f o r(Da ta Snapshot s u b Men uSnap s: ca tegoryS naps.getChildren() )  {              for( D at aSn a ps h otit e mSn a p s : subMenuSnap s.getChild re n () ) {
               for (D ataSn a pshot p roductSna ps : item Sn aps. g e tCh ildren()){
                  Produ ctproduc t= p roduc tSnaps . get Value (Produ ct .class );
                     productList .add(p roduc t); 
                }
             }
        } 
        re t ailCh ain. s etProduct s (p rod u c tL ist);
       reta ilC h ainLis t.ad d(retailChain);
      }         }
    @O ve rride
      pu bli cv o id onCan ce lled(Databa seErrorda t abase Error)  {
       Lo g . w( " databa se e rro r: ", "on Can ce l led", d at ab a seErro r.to 
 _ _at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

A:

When you set_rule "auth!=_null"_it means_user_cannot access database_before they finished_sign in.
And Sign In_process is an_asynchronous,_It means the complete listener will not called right away.
To solve your problem is_simply_move the_code_that_read database inside on complete_listener.
public void load(final Context context)_{

 _fireBaseAuthenticate(context);

}

public void fireBaseAuthenticate(final Context context) {
  mAuth_=_FirebaseAuth.getInstance();
  mAuth.signInAnonymously()
_   .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
   _     _  @Override
___   _     public_void onComplete(@NonNull Task<AuthResult> task) {
 _      _     _ if (task.isSuccessful()) {
 _ _    _  _ _  _  // load the data
_  _     __  ___ _ loadFromDB();
 __ __     __   } else {
 _   __   _    _   // If sign_in fails,_display a_message to the user.

       _     _  }

 _ __  __ _ }
  });

}

private void loadFromDB(){
 _database =_FirebaseDatabase.getInstance();
  databaseReference = database.getReference();
 _databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
 __   @Override
  _   public void onDataChange(DataSnapshot_dataSnapshot) {
   ___  for (DataSnapshot categorySnaps_: dataSnapshot.getChildren()) {
   _  _     RetailChain retailChain_=_new RetailChain();
    __     _retailChain.setName(categorySnaps.getKey());
__    _     for_(DataSnapshot subMenuSnaps : categorySnaps.getChildren()) {
    _  _    ___ for (DataSnapshot itemSnaps : subMenuSnaps.getChildren()) {
   _ _  _         _ for (DataSnapshot productSnaps : itemSnaps.getChildren()) {
_          _       _    Product product =_productSnaps.getValue(Product.class);
   __      ____  _  _  _productList.add(product);
 _  _ _  __         }
        _     _ }
   __  _   _}
       _    retailChain.setProducts(productList);
    __ _   _retailChainList.add(retailChain);
 _ _  _ }_ _ _ 
     _}

_     @Override
   ___public_void onCancelled(DatabaseError databaseError)_{
  _  _  Log.w("database_error:_", "onCancelled", databaseError.to