title: NavigationView -> headerLayout -> ImageButton -> onclick results in IllegalStateException in ContextThemeWrapper
body: <p>In the <code>headerLayout</code> of a <code>NavigationView</code> (on the left side of a <code>DrawerLayout</code> app) I have an <code>ImageButton</code>, which should represent ability to add a social network account:</p>
  
  <p><a href="https://i.stack.imgur.com/tcXWD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tcXWD.png" alt="enter image description here"></a></p>
  
  <p>Here is the <strong>activity_main.xml</strong> with the <code>NavigationView</code>:</p>
  
  <pre><code>&lt;android.support.design.widget.NavigationView
      android:id="@+id/left_drawer"
      android:layout_height="match_parent"
      android:layout_width="wrap_content"
      android:layout_gravity="start"
      android:fitsSystemWindows="true"
      android:background="#FFF"
      app:itemIconTint="@color/drawer_item_text"
      app:itemTextColor="@color/drawer_item_text"
      app:headerLayout="@layout/header_left"
      app:menu="@menu/drawer_left"/&gt;
  </code></pre>
  
  <p>And here the <strong>header_left.xml</strong> with the <code>ImageButton</code>:</p>
  
  <pre><code>&lt;ImageButton
      android:id="@+id/account"
      android:src="@drawable/ic_account_plus_white_24dp"
      android:background="@color/drawer_header_bg"
      android:onClick="showAccounts"
      android:padding="0dp"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="right|bottom"
      /&gt;
  </code></pre>
  
  <p>In the <strong>MainActivity.java</strong> I have defined the click handler method:</p>
  
  <pre><code>public void showAccounts(View v) {
      Log.d(TAG, "accounts button clicked");
  }
  </code></pre>
  
  <p>Unfortunately, the app crashes on the <code>ImageButton</code> click with:</p>
  
  <pre><code>java.lang.IllegalStateException: Could not find a method showAccounts(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.ImageButton with id 'account'
          at android.view.View$1.onClick(View.java:4013)
          at android.view.View.performClick(View.java:4785)
          at android.view.View$PerformClick.run(View.java:19858)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:155)
          at android.app.ActivityThread.main(ActivityThread.java:5696)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
   Caused by: java.lang.NoSuchMethodException: showAccounts [class android.view.View]
          at java.lang.Class.getMethod(Class.java:664)
          at java.lang.Class.getMethod(Class.java:643)
          at android.view.View$1.onClick(View.java:4006)
              at android.view.View.performClick(View.java:4785)
              at android.view.View$PerformClick.run(View.java:19858)
              at android.os.Handler.handleCallback(Handler.java:739)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:155)
              at android.app.ActivityThread.main(ActivityThread.java:5696)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
  </code></pre>
  
  <p>Why does it happen and how to work around the problem please? (Besides adding <code>onClickListener</code> in <strong>MainActivity.java</strong>).</p>
  
  <p>I have another <code>ImageButton</code> in the <code>Toolbar</code> of the same app - and its <em>onclick</em> handler is called in <strong>MainActivity.java</strong> just fine. </p>