title: Cannot find reason for NullPointerException in Android App
body: <p>I am programming an Android app. Some users get a <code>NullPointerException</code> on Startup, but I cannot find the reason (on my Phone and 6 different AVDs it works and I cannot reproduce the exception so I could take a look on the error in my Android Studio and play around there).</p>
  
  <p>The PlayConsole shows me this errorlog for my users. My knowledge is too small to get the reason just out of this log. Can anyone see the reason?</p>
  
  <p><strong>Errorlog:</strong></p>
  
  <pre><code>java.lang.NullPointerException: 
    at de.schwembo.beercount.AuswertungFragment.onCreateView (AuswertungFragment.java:85)
    at androidx.fragment.app.Fragment.performCreateView (Fragment.java:2600)
    at androidx.fragment.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:881)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManagerImpl.java:1238)
    at androidx.fragment.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1303)
    at androidx.fragment.app.BackStackRecord.executeOps (BackStackRecord.java:439)
    at androidx.fragment.app.FragmentManagerImpl.executeOps (FragmentManagerImpl.java:2079)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether (FragmentManagerImpl.java:1869)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute (FragmentManagerImpl.java:1824)
    at androidx.fragment.app.FragmentManagerImpl.execSingleAction (FragmentManagerImpl.java:1696)
    at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss (BackStackRecord.java:299)
    at androidx.fragment.app.FragmentPagerAdapter.finishUpdate (FragmentPagerAdapter.java:235)
    at androidx.viewpager.widget.ViewPager.populate (ViewPager.java:1244)
    at androidx.viewpager.widget.ViewPager.populate (ViewPager.java:1092)
    at androidx.viewpager.widget.ViewPager.onMeasure (ViewPager.java:1622)
    at android.view.View.measure (View.java:22286)
    at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6668)
    at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild (CoordinatorLayout.java:760)
    at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild (HeaderScrollingViewBehavior.java:99)
    at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild (AppBarLayout.java:1892)
    at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure (CoordinatorLayout.java:831)
    at android.view.View.measure (View.java:22286)
    at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6668)
    at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
    at androidx.appcompat.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:143)
    at android.view.View.measure (View.java:22286)
    at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6668)
    at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1539)
    at android.widget.LinearLayout.measureVertical (LinearLayout.java:823)
    at android.widget.LinearLayout.onMeasure (LinearLayout.java:702)
    at android.view.View.measure (View.java:22286)
    at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6668)
    at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
    at android.view.View.measure (View.java:22286)
    at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6668)
    at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1539)
    at android.widget.LinearLayout.measureVertical (LinearLayout.java:823)
    at android.widget.LinearLayout.onMeasure (LinearLayout.java:702)
    at android.view.View.measure (View.java:22286)
    at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:6668)
    at android.widget.FrameLayout.onMeasure (FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure (DecorView.java:837)
    at android.view.View.measure (View.java:22286)
    at android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:2646)
    at android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:1674)
    at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1933)
    at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1558)
    at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7463)
    at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1041)
    at android.view.Choreographer.doCallbacks (Choreographer.java:847)
    at android.view.Choreographer.doFrame (Choreographer.java:774)
    at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1027)
    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:7555)
    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>The affected function (AuswertungFragment.java:85) is this, it is inside of the <code>onCreateView()</code> method:</p>
  
  <pre><code>// Spinner for Months differentiation
  spinnerMonat.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parentView, View selectedItemView, int position, long id) {
         // IF statement for year/gesamt selection
         if (spinnerMonat.getSelectedItem().toString().equals(getString(R.string.gesamt))) {
             for (int i = 0; i &lt; 12; i++) {
                 alleDatenAusCursor = dataSource.zaehleAllesZuCursor(dataSource.getCursorFuerMonat(i + 1));
                 anzahlZuMonate[i] = String.valueOf(alleDatenAusCursor[0]);
                 preisZuMonate[i] = String.valueOf(alleDatenAusCursor[1]);
                 mengeZuMonate[i] = String.valueOf(alleDatenAusCursor[2]);
             }
             fuelleLV4(monate, anzahlZuMonate, preisZuMonate, mengeZuMonate);
         } else {
             for (int i = 0; i &lt; 12; i++) {
                 alleDatenAusCursor = dataSource.zaehleAllesZuCursor(dataSource.getCursorFuerMonatJahr(spinnerMonat.getSelectedItem().toString(), i + 1));
                 anzahlZuMonate[i] = String.valueOf(alleDatenAusCursor[0]);
                 preisZuMonate[i] = String.valueOf(alleDatenAusCursor[1]);
                 mengeZuMonate[i] = String.valueOf(alleDatenAusCursor[2]);
             }
             fuelleLV4(monate, anzahlZuMonate, preisZuMonate, mengeZuMonate);
         }
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parentView) {
         for (int i = 0; i &lt; 12; i++) {
             alleDatenAusCursor = dataSource.zaehleAllesZuCursor(dataSource.getCursorFuerMonat(i + 1));
             anzahlZuMonate[i] = String.valueOf(alleDatenAusCursor[0]);
             preisZuMonate[i] = String.valueOf(alleDatenAusCursor[1]);
             mengeZuMonate[i] = String.valueOf(alleDatenAusCursor[2]);
         }
         fuelleLV4(monate, anzahlZuMonate, preisZuMonate, mengeZuMonate);
      }
  });
  </code></pre>
  
  <p>dataSource is initialized in the <code>onCreate()</code> Method like this:</p>
  
  <blockquote>
    <p><code>dataSource = new DatabaseHandler(getActivity());</code></p>
  </blockquote>
  
  <p>Spinner is initialized in the <code>onCreateView()</code> Method like this:</p>
  
  <blockquote>
    <p><code>final Spinner spinnerMonat = rootView.findViewById(R.id.spinnerMonth2);</code></p>
  </blockquote>