title: Dynamically switch Firebase Reference
body: <p>the code below is suppose to change my database reference depending on my userlvlid however whenever I run the activity which contains this part, the app crashes i do not understand why I cant change my "ref" anymore.</p>
  
  <pre><code>        ref = FirebaseDatabase.getInstance().getReference("users");
                          ref.child(uid).child("userlvlid").addValueEventListener(
                                  new ValueEventListener() {
                                      @Override
                                      public void onDataChange(DataSnapshot dataSnapshot) {
                                           userlvlid = dataSnapshot.getValue().toString();
                                          if(userlvlid.compareTo("1")==0){
                                              Toast.makeText(MainScreen.this,userlvlid,
                                                      Toast.LENGTH_LONG).show();
                                              ref = FirebaseDatabase.getInstance().getReference("bystander");
                                          }
                                          else if(userlvlid.compareTo("2")==0){
                                              Toast.makeText(MainScreen.this,userlvlid,
                                                      Toast.LENGTH_LONG).show();
                                              ref = FirebaseDatabase.getInstance().getReference("firstaider");
                                          }
                                          else if(userlvlid.compareTo("3")==0){
                                              Toast.makeText(MainScreen.this,userlvlid,
                                                      Toast.LENGTH_LONG).show();
                                              ref = FirebaseDatabase.getInstance().getReference("ambulance");
                                          }
                                          else{
                                           //do nothing
                                          }
                                      }
  
                                      @Override
                                      public void onCancelled(DatabaseError databaseError) {
  
                                      }
                                  }
                          );
  </code></pre>
  
  <p>ERROR REPORT:
  <a href="https://i.stack.imgur.com/tEqzz.png" rel="nofollow"><img src="https://i.stack.imgur.com/tEqzz.png" alt="enter image description here"></a></p>