title: How to fix Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
body: <p>I tried to get values firebase and put it into TextView and when I execute my program the exception:</p>
  
  <blockquote>
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
  </code></pre>
  </blockquote>
  
  <p>I know that this question is duplicated but I don't found any answer on others.</p>
  
  <p>My code:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_notificationdisplay);
      FirebaseApp.initializeApp(this);
      final TextView title = (TextView)findViewById(R.id.title);
      final TextView text = (TextView)findViewById(R.id.text);
      //--------------------String text1="";
      FirebaseDatabase.getInstance().getReference().child("notification").child("contenu").addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              Log.v("text:",dataSnapshot.getValue().toString());
              text.setText(dataSnapshot.getValue(String.class));
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
      });
      //-----------------title
      FirebaseDatabase.getInstance().getReference().child("notification").child("title").addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              Log.v("title:",dataSnapshot.getValue().toString());
              title.setText(dataSnapshot.getValue(String.class));
  
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
  
      });
  }
  </code></pre>