I have the following issue: I have a class, trying to use reflection to call one of its OWN protected methods, and I'm getting an exception: java.lang.IllegalAccessException: access to method denied
Can someone maybe shed some light on this?
The base class:
public abstract class BaseReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// invoke the correct event method:
Method method;
try {
method = this.getClass().getDeclaredMethod("testMethod");
method.invoke(this);
} catch (Throwable ex) {
// ... display exception message
}
}
protected void testMethod() {
}
}
The derived concrete class:
class MyReceiver extends BaseReceiver {
@Override
protected void testMethod() {
// display error message
}
}