InflateException: Couldn't resolve menu item onClick handler

后端 未结 7 802
情书的邮戳
情书的邮戳 2020-12-08 19:12

I asked this question 6 years ago. In the meantime Android development best practices have changed, and I have become a better developer.

Since then, I have realized

7条回答
  •  一个人的身影
    2020-12-08 19:56

    In my case, the AndroidManifest.xml of my application (kick-started by the default Eclipse assistant) contained android:theme="@style/AppTheme" in the block.

    When debugging the cause of the problem, it turned out that the line

    mMethod = c.getMethod(methodName, PARAM_TYPES);
    

    in android.view.MenuInflater/InflatedOnMenuItemClickListener was called with c not being my Activity class but a dubious android.view.ContextThemeWrapper (which of course doesn't contain the onClick handler).

    So, I removed the android:theme and everything worked.

提交回复
热议问题