title: Bottom nav view fragment NullPointerException
body: <p>In my one of my fragments I have a toggle button in the xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.stefan.findage.piano"&gt;
  
      &lt;!-- TODO: Update blank fragment layout --&gt;
  
      &lt;ToggleButton
          android:id="@+id/metronome"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="ToggleButton" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>And</p>
  
  <pre><code>toggleButton = (ToggleButton) getView().findViewById(R.id.metronome);
  </code></pre>
  
  <p>But when trying to open the fragment it crashes and the logcat shows that it was a </p>
  
  <blockquote>
    <p>java.lang.NullPointerException:Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference</p>
  </blockquote>
  
  <p>Here's the Main Activity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          BottomNavigationView bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottomView);
          bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                  switch (item.getItemId())
                  {
                      case R.id.moosic:
                          rhythm fragmentone = new rhythm();
                          android.support.v4.app.FragmentTransaction fragmentTransaction3 = getSupportFragmentManager().beginTransaction();
                          fragmentTransaction3.replace(R.id.frame, fragmentone, "rhythm");
                          fragmentTransaction3.commit();
                          return true;
                      case R.id.call:
                          intervals fragmenttwo = new intervals();
                          android.support.v4.app.FragmentTransaction fragmentTransaction2 = getSupportFragmentManager().beginTransaction();
                          fragmentTransaction2.replace(R.id.frame, fragmenttwo, "intervals");
                          fragmentTransaction2.commit();
                          return true;
                      case R.id.thinga:
                          piano fragmentthree = new piano();
                          android.support.v4.app.FragmentTransaction fragmentTransaction1 = getSupportFragmentManager().beginTransaction();
                          fragmentTransaction1.replace(R.id.frame, fragmentthree, "piano");
                          fragmentTransaction1.commit();
                          return true;
  
                  }
                  return false;
              }
          });
  
      }
  
  }
  </code></pre>