title: Rotation Animation on menu item in Action Bar error
body: <p>I need help with an refresh button in my action bar. I already have this button but I want to let it rotate onclick. I've wrote this code here but I'm getting an error and the app is crashing:</p>
  
  <p>The error:</p>
  
  <blockquote>
    <p><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference</code></p>
  </blockquote>
  
  <p>Mx XML:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:compat="http://schemas.android.com/tools"&gt;
  
      &lt;item
          android:id="@+id/menu_reloadbutton"
          android:icon="@drawable/ic_menu_reloadentry"
          android:title="@string/menu_reloadentry"
          app:showAsAction="ifRoom"/&gt;
  
  &lt;/menu&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>My code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  
          inflater.inflate(R.menu.menu_training, menu);
  
          // Declare ImageView and Animation for rotation animation
          MenuItem reloadButton = (MenuItem) menu.findItem(R.id.menu_reloadbutton);
          final Animation rotation = AnimationUtils.loadAnimation(getActivity(), R.anim.animation_rotate);
  
          if (reloadButton != null) {
              //reloadButton.setImageResource(R.drawable.ic_menu_reloadentry);
              reloadButton.getActionView().setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      rotation.setRepeatCount(Animation.INFINITE);
                      view.startAnimation(rotation);
                  }
              });
          }
      }</code></pre>
  </div>
  </div>
  </p>