Sorry for the long answer but I think its useful to explain how to dig into the Android framework to debug the problem.
The code that throws this exception can be accessed here:
http://androidxref.com/6.0.1_r10/xref/frameworks/base/core/java/android/view/View.java
4452 try {
4453 mMethod.invoke(mHostView.getContext(), v);
4454 } catch (IllegalAccessException e) {
4455 throw new IllegalStateException(
4456 "Could not execute non-public method for android:onClick", e);
4457 } catch (InvocationTargetException e) {
4458 throw new IllegalStateException(
4459 "Could not execute method for android:onClick", e);
4460 }
Reflection and its use in click listeners
Basically what it is doing is invoking a method based on a string using reflection. This method is one that is defined by an app developer to respond to a button being clicked. This is commonly done since you can specify an onClickListener method via XML, for example you can say invoke "goDoWhatever" instead of the usual "onClick". Reflection takes a string representation of this method and tries to call a method on a specified class of that name.
A reflection error occurs when the desired method does not exist, for example if you get the name wrong, the method is private, or the parameters are different.
Note that in this case there are two different exceptions, one for a non public method and then another for not being able to execute it. I don't know why your stack trace doesn't have a message associated with the IllegalStateException but manufacturers can modify this code if they desire.
I suspect that you have a method of the correct name since the resolve method function throws a different error if the name is wrong:
4463 @NonNull
4464 private Method resolveMethod(@Nullable Context context, @NonNull String name) {
4465 while (context != null) {
4466 try {
4467 if (!context.isRestricted()) {
4468 return context.getClass().getMethod(mMethodName, View.class);
4469 }
...
4485 throw new IllegalStateException("Could not find method " + mMethodName
4486 + "(View) in a parent or ancestor Context for android:onClick "
4487 + "attribute defined on view " + mHostView.getClass() + idText);
4488 }
4489 }
So this leaves us with two possibilities that I can think of: the method it finds has the wrong signature or the method it finds is static/private.
How I would go about debugging this:
I am guessing you specify a click listener in your xml somewhere (look for "android:onClick=" in your xml files. Then search your application for all methods of the same name and make sure that they take a single View as a parameter (make sure you import "android.view.View" in the file too as importing the wrong view could cause this). Also make sure they are not static. It is also probably worth looking for things that are private as this can also cause problems but based on your stack trace it seems less likely.
Why this problem may be hard to reproduce:
If you notice the method "resolveMethod" in the android framework simply returns the first method of the same name, so whereas it is valid java to have a class:
class Foo{
void bar(String s){}
void bar(View s){}
A method signature consists of a name (such as "bar") and a list of parameters, (in this case a list with one item "View" or a list with one item "String").
This Android framework code might find "void bar(String s)" instead of "void bar(View s)". This can cause a hard to reproduce bug since the order in which reflection finds methods is non deterministic (Java reflection: Is the order of class fields and methods standardized?). So you may have a hard time reproducing it since a specific device probably deterministically iterates through them in some way but not neccessarily the same way as some other device/implementation.
I hope this helps! Please let me know how it turns out, I am a graduate student doing research on software defects such as this one so details are quite useful to me.