title: Null pointer exception on spinner click
body: <p>I am trying to bind data from Parse.com to a spinner. I have set up the ArrayList and validated that the data is successfully retrieved by the app in proper format. But when I click on the spinner, the app crashes with the following error.</p>
  
  <pre><code>        java.lang.NullPointerException
          at android.view.ViewGroup.canViewReceivePointerEvents(ViewGroup.java:2140)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1492)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1535)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1535)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1535)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1535)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1535)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1535)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
          at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:1535)
          at android.view.View.dispatchGenericMotionEvent(View.java:7772)
          at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchGenericMotionEvent(PhoneWindow.java:2076)
          at com.android.internal.policy.impl.PhoneWindow.superDispatchGenericMotionEvent(PhoneWindow.java:1525)
          at android.app.Activity.dispatchGenericMotionEvent(Activity.java:2494)
          at android.support.v7.internal.view.WindowCallbackWrapper.dispatchGenericMotionEvent(WindowCallbackWrapper.java:70)
          at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchGenericMotionEvent(PhoneWindow.java:2030)
          at android.view.View.dispatchPointerEvent(View.java:7888)
          at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
          at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
          at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
          at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
          at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
          at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512)
          at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483)
          at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612)
          at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
          at android.os.MessageQueue.nativePollOnce(Native Method)
          at android.os.MessageQueue.next(MessageQueue.java:138)
          at android.os.Looper.loop(Looper.java:123)
          at android.app.ActivityThread.main(ActivityThread.java:5001)
          at java.lang.reflect.Method.invoke
  </code></pre>
  
  <p>I don't get any reference to the line of code which is throwing a null pointer exception.</p>
  
  <p>This is the snippet which sets the spinner.</p>
  
  <pre><code>  ArrayList&lt;String&gt; spinnerArray =  new ArrayList&lt;String&gt;();
      for (int i = 0 ; i &lt; photoPrintsList.size(); i++ ) {
          spinnerArray.add(photoPrintsList.get(i).getSizes());
      }
  
  
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
              this, android.R.layout.simple_spinner_item, spinnerArray);
  
   adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      Spinner sItems = (Spinner) findViewById(R.id.select_size_spinner);
      sItems.setAdapter(adapter);
  </code></pre>
  
  <p>and the setOnSelectedListener</p>
  
  <pre><code> sItems.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              Toast.makeText(getApplicationContext(),"",Toast.LENGTH_SHORT).show();
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
  
          }
  
  
      });
  </code></pre>
  
  <p>What am I doing wrong? I have debugged 20 times but can't figure out what's wrong. Please help.</p>
  
  <p><strong>Extended code:-</strong></p>
  
  <pre><code>List&lt;PhotoPrintsConfig&gt; photoPrintsList;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_size);
      sharedPref=  getSharedPreferences("Images",MODE_PRIVATE);
      /*Set the action bar with the Spannable String class and add custom typeface to it.*/
      setActionBar();
      /* Get count of the images in the shared preferences. Create an arraylist to hold the images. */
      imageSelectedCount = getImageSelectedCount();
      /* Set the adapter*/
      setAdapter();
  
  
  
      photoPrintsList = new ArrayList&lt;PhotoPrintsConfig&gt;();
      ParseQuery&lt;ParseObject&gt; parseQuery = new ParseQuery&lt;ParseObject&gt;("PhotoPrints");
      parseQuery.orderByAscending("Sizes");
      parseQuery.findInBackground(new FindCallback&lt;ParseObject&gt;() {
          @Override
          public void done(List&lt;ParseObject&gt; list, ParseException e) {
              if (e == null) {
                  int count = 0;
                  for (ParseObject p : list) {
                      PhotoPrintsConfig prints = new PhotoPrintsConfig();
                      prints.setSizes(p.getString("Sizes"));
                        Log.d(TAG + " Data from parse " + count, prints.getSizes());
                      prints.setQuality((ArrayList) p.get("Quality"));
                      for (int i = 0; i &lt; prints.getQuality().size(); i++) {
                            Log.d(TAG + " Data from Parse" + count, i + " " + prints.getQuality().get(i).toString());
                      }
                      prints.setPaperType((ArrayList) p.get("PaperType"));
                      for (int i = 0; i &lt; prints.getPaperType().size(); i++) {
                           Log.d(TAG + " Data from parse" + count, i + " " + prints.getPaperType().get(i).toString());
                      }
                      prints.setPrices((ArrayList) p.get("Prices"));
                      for (int i = 0; i &lt; prints.getPrices().size(); i++) {
                           Log.d(TAG + " data from parse " + count , i + " " + prints.getPrices().get(i).toString());
                      }
                      count++;
                      photoPrintsList.add(prints);
                      Log.d(TAG, String.valueOf(photoPrintsList.size()));
                  }
                  setUpSpinners();
              } else {
  
              }
          }
  
      });
  
  
  
  }
  
  @Override
  protected void onDestroy() {
      super.onDestroy();
  
      if(settingsDialog!= null){
          settingsDialog.dismiss();
      }
  
  }
  
  private void setUpSpinners() {
  
  
     // PhotoPrintsConfig photoPrintsConfig = new PhotoPrintsConfig();
  
      ArrayList&lt;String&gt; spinnerArray =  new ArrayList&lt;String&gt;();
      for (int i = 0 ; i &lt; photoPrintsList.size(); i++ ) {
          spinnerArray.add(photoPrintsList.get(i).getSizes());
      }
  
  
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
              this, android.R.layout.simple_spinner_item, spinnerArray);
  
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      Spinner sItems = (Spinner) findViewById(R.id.select_size_spinner);
      sItems.setAdapter(adapter);
  
  
     /* sItems.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              Toast.makeText(getApplicationContext(),"",Toast.LENGTH_SHORT).show();
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
  
          }
  
  
      });*/
      //selectedListener(sItems1,spinnerArray1);
      //selectedListener(sItems2,spinnerArray2);
  
  
  }
  </code></pre>