I am using reflection to invoke particular methods in runtime. Code looks like:
method = workClass.getMethod(methodName, parameterTypes);
retrivedValue = method.invoke(retrivedValue, parameterValues);
Most of the time 99% cases, it works properly. But, sometimes the following error is happened:
at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)
It is strange because the some method will be invoked many times correctly and suddenly for the some method previous error will be thrown.
Does anyone know what problem could be?
Thank you in advance.
Presumably you know what the error means.
Could be that most of the time you go down code path A in the call tree (in the reflected code).
Sometimes you go down code path B and that path is attempting to load a bad class.
Thanks for thoughts.
I do not have idea what the error means.
I put break point and I saw that:
methodName is: getInstance
Can you please tell me do you see some solution for this problem?
A couple things to think about:
Are you always executing the method from the same threads? The javadocs refer to the fact it can be a security issue. If you're running in some type of sandbox, or if a given thread has restricted access, it could cause this exception.
Another possibility is you're running out of memory in some strange way. Usually you'll get an 'OutOfMemoryError' thrown, but that is if the JVM runs out of memory. It could be something strange happening with lack of memory (or temporary space etc) on the system. Have you tried executing the code on different machines? The fact that you said it happens many times, then has a problem makes me believe there is a memory leak somewhere (or a space issue).
I have list of items. With every item selection, I have to create panel with different components on it dynamically.
I am creating thread to build GUI on the fly. So, in the thread:
- I am repeating the following process:
1.I instantiate corresponding component(I don't know in advance which it will be - JList, JTable,...),
2.place it on the panel,
3.using reflection I get data value, and
4.populate component with retrieved value.
- In event dispatch thread, I am placing panel on corresponding tab.
I have not tried executing the code on different machines but this project went in production, so many people use it
and so far nobody complained.