title: ID does not reference a View inside this Activity
body: <p>I keep getting an IllegalArgumentException in my MainActivity code, please help me! The error is being shown on the line </p>
  
  <pre><code>    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
  </code></pre>
  
  <p>I am trying to add in the QR code reader into the Main Activity, but when I did so, this error popped up</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private AppBarConfiguration mAppBarConfiguration;
      private SharedPreferences appData;
      private Button scan_button;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.fragment_scan);
          scan_button = (Button) findViewById(R.id.btnScan);
          final Activity activity = this;
          scan_button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  IntentIntegrator integrator = new IntentIntegrator(activity);
                  integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
                  integrator.setPrompt("Scan");
                  integrator.setCameraId(0);
                  integrator.setBeepEnabled(false);
                  integrator.setBarcodeImageEnabled(false);
                  integrator.initiateScan();
              }
          });
  
          Toolbar toolbar = findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          /*FloatingActionButton fab = findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });
           */
  
          DrawerLayout drawer = findViewById(R.id.drawer_layout);
          NavigationView navigationView = findViewById(R.id.nav_view);
          // Passing each menu ID as a set of Ids because each
          // menu should be considered as top level destinations.
          mAppBarConfiguration = new AppBarConfiguration.Builder(
                  R.id.nav_home, R.id.nav_transaction, R.id.nav_qrcode,
                  R.id.nav_login, R.id.nav_logout, R.id.nav_signup, R.id.nav_rewards, R.id.nav_scan)
                  .setDrawerLayout(drawer)
                  .build();
          NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
          NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
          NavigationUI.setupWithNavController(navigationView, navController);
  
          appData = getSharedPreferences("appData", this.MODE_PRIVATE);
          SharedPreferences.Editor editor = appData.edit();
          editor.putFloat("Point", 0);
          //editor.putBoolean("SAVE_LOGIN_DATA", checkBox.isChecked());
          editor.putString("ID", "");
          editor.putString("PWD", "");
          editor.apply();
  
          //Navigation.findNavController(navigationView).navigate(R.id.nav_login);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onSupportNavigateUp() {
          NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
          return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                  || super.onSupportNavigateUp();
      }
  
      public boolean onChangeMenuItem() {
          NavigationView navigationView = findViewById(R.id.nav_view);
          Menu menu = navigationView.getMenu();
          MenuItem nav_dashboard = menu.findItem(R.id.nav_login);
          nav_dashboard.setVisible(false);
  
          return true;
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
          if (result != null) {
              if (result.getContents() == null) {
                  Toast.makeText(this, "You Cancelled the Scan", Toast.LENGTH_LONG).show();
              } else {
                  Toast.makeText(this, result.getContents(), Toast.LENGTH_LONG).show();
                  String scanResult = data.getStringExtra("SCAN_RESULT");
                  int pointsAdded = Integer.parseInt(scanResult);
              }
          }
          else {
              super.onActivityResult(requestCode, resultCode, data);
          }
      }
  }
  </code></pre>