title: Java Null Pointer Exception on 'android.view.Window$Callback android.view.Window.getCallback()'
body: <p>I was trying to add a collapsing Toolbar to a Fragment, but the app crashed as soon as I opened the Fragment:
  This is the error I get:     </p>
  
  <pre><code>2018-10-19 18:05:38.950 13301-13301/io.github.davidwickerhf.diceroller E/AndroidRuntime: FATAL EXCEPTION: main
  Process: io.github.davidwickerhf.diceroller, PID: 13301
  java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
      at androidx.appcompat.app.AppCompatDelegateImpl.&lt;init&gt;(AppCompatDelegateImpl.java:249)
      at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
      at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
      at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:191)
      at io.github.davidwickerhf.diceroller.ProfileFragment.onCreateView(ProfileFragment.java:36)
      at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
      at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
      at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
      at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
      at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
      at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
      at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
      at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
      at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
      at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
      at android.os.Handler.handleCallback(Handler.java:809)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:166)
      at android.app.ActivityThread.main(ActivityThread.java:7436)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
  </code></pre>
  
  <p>Fragment Java:</p>
  
  <pre><code>public class ProfileFragment extends Fragment {
  
      private MainActivity mMainActivity;
      private SettingsViewModel settingsViewModel;
      private SettingAdapter adapter;
      private CoordinatorLayout coordinatorLayout;
      private View fragmentView;
  
      private TabLayout mTabLayout;
      private ViewPager mViewPager;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          fragmentView = inflater.inflate(R.layout.fragment_profile, container, false);
  
          mMainActivity = new MainActivity();
  
          androidx.appcompat.widget.Toolbar mToolbar = fragmentView.findViewById(R.id.profile_toolbar);
          mMainActivity.setSupportActionBar(mToolbar);
  
          mViewPager = (ViewPager) fragmentView.findViewById(R.id.viewpager);
          ViewPagerAdapter adapter = new ViewPagerAdapter(mMainActivity.getSupportFragmentManager());
          adapter.AddFragment(new ProfileInfoFragment(), "Profile");
          adapter.AddFragment(new ProfileMessagingFragment(), "Messages");
          mViewPager.setAdapter(adapter);
          mTabLayout = (TabLayout) fragmentView.findViewById(R.id.tab_layout_profile);
          mTabLayout.setupWithViewPager(mViewPager);
  
          return fragmentView;
      }
  }
  </code></pre>
  
  <p>The Fragment XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 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"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  tools:context=".ProfileFragment"
  android:orientation="vertical"&gt;
  
  &lt;com.google.android.material.appbar.AppBarLayout
      android:id="@+id/appBar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme"
      app:toolbarId="@id/profile_toolbar"&gt;
  
      &lt;com.google.android.material.appbar.CollapsingToolbarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:fitsSystemWindows="true"
          app:contentScrim="?attr/colorPrimary"
          app:layout_scrollFlags="scroll|exitUntilCollapsed"
          app:titleEnabled="false"&gt;
  
          &lt;ImageView
              android:id="@+id/background_image_Toolbar"
              android:layout_width="match_parent"
              android:layout_height="256dp"
              android:fitsSystemWindows="true"
              android:scaleType="centerCrop"
              app:layout_collapseMode="parallax" /&gt;
  
          &lt;androidx.appcompat.widget.Toolbar
              android:layout_marginTop="24dp"
              android:id="@+id/profile_toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              app:layout_collapseMode="pin"
              app:popupTheme="@style/AppTheme" /&gt;
  
      &lt;/com.google.android.material.appbar.CollapsingToolbarLayout&gt;
  
      &lt;com.google.android.material.tabs.TabLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:tabGravity="fill"
          app:tabMode="fixed"
          android:id="@+id/tab_layout_profile"
          app:tabTextColor="@color/greyText"
          app:tabIndicatorColor="@color/greyText"
          android:background="#fafafa"
          android:elevation="0dp"&gt;
  
      &lt;/com.google.android.material.tabs.TabLayout&gt;
  
  &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
  
  
  
  
  &lt;androidx.viewpager.widget.ViewPager
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/viewpager"&gt;
  
      &lt;androidx.constraintlayout.widget.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
  
  
  
  
  
  
  
  
  
  
  
  
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  
  
  &lt;/androidx.viewpager.widget.ViewPager&gt;
  </code></pre>
  
  <p></p>
  
  <p>Please help?</p>