title: android - Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
body: <p>I'm trying to set the text of the navigation drawer activity from the fetched data on my database, but when i try to do so, it throws the following error </p>
  
  <blockquote>
    <p>Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference</p>
  </blockquote>
  
  <p>Am I missing something or did I do something wrong in my code?</p>
  
  <pre><code>public void fetchDb(){
      String email = getIntent().getExtras().getString("EMAIL");
  
      TextView txtName = findViewById(R.id.nameText);
      TextView txtEmail = findViewById(R.id.emailText);
      String name, ema;
  
      DatabaseHelper dbh = new DatabaseHelper(this);
  
      newDb = dbh.getReadableDatabase();
      Cursor c = newDb.rawQuery("SELECT * FROM user WHERE user_email = \'" + email+"\'", null);
      if (c.moveToFirst()){
          do {
              name = c.getString(1);
              ema = c.getString(2);
  
              txtName.setText(name);
              txtEmail.setText(ema);
  
          } while(c.moveToNext());
      }
      c.close();
      newDb.close();
  }
  </code></pre>