title: IllegalAccessException when using call dynamic methods
body: <p>I am trying to use Reflection in Java but I am getting a weird error. What are the possible issues when I get an error that says:</p>
  
  <pre><code>java.lang.IllegalAccessException: Class com.myapp.core.utils.EventDispatcher can not access a member of class appApp$1 with modifiers "public"
  at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  </code></pre>
  
  <p>I just trying to create my own EventDispatcher class and inside it, the part that I used reflection, which is also the line of code that causes the problem is:</p>
  
  <pre><code>public void dispatchEvent(Event e, String callMethName) {
  IEventListener list = ((IEventListener)listeners[i]);
                  list.getClass().getMethod(callMethName, Event.class).invoke(list, e);
  }
  </code></pre>
  
  <p>On my main class, I have something that calls addListener which will just add the listener into a list in the EventDispatcher class this way:</p>
  
  <pre><code>try {
  obj.addListener("onTestHandler", new MyTestEventListener(){
      @Override
      public void onTestHandler(Event e) {
          System.out.println("hello!");
      }
  });
  } catch (SecurityException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>So the first parameter that says "onTestHandler" will pass into the EventDispatcher class and eventually as part of the parameter callMethName in the dispatchEvent method, which will call the method dynamically.</p>
  
  <p>The passing of methods and everything is correct. It is the part that has the reflection somehow has problems. It seems to be able to find the method. But for some reason, throws an IllegalAccessException and cannot call the method.</p>
  
  <p>Why is it like this?</p>
  
  <p>Thanks.</p>