Problem description
This exception occurs when the Method.invoke(obj, args…)
method is used and an exception inside the method is not caught.
Solution
This exception occurs when reflection is used to invoke the method and an exception inside the method is not caught. We recommend that you use the try catch block to catch the exception and handle it.
Sample code
public static void main(String[] args) {
try {
Class<?> clazz = Class.forName("com.alibaba.test");
Method method = clazz.getMethod("run", int.class);
method.invoke(clazz.newInstance(), -1);
} catch (InvocationTargetException e) {
System.out.println ("here an exception inside the called method occurs and is not caught");
e.printStackTrace();
}
}
Example:
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.app.ActivityThread.pauseGC(ActivityThread.java:5525)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Native method not found: dalvik.system.VMRuntime.pauseGc:(Ljava/lang/String;)I
at dalvik.system.VMRuntime.pauseGc(Native Method)
... 15 more
No solution can be provided based on the stack information of this exception. This exception is a bug introduced by Samsung Android versions 4.4.2 and 4.4.4. The reason is that the function is not found when reflection is used to invoke the pauseGc()
native method in line 5525 of the ActivityThread file. When a GLSurfaceView is invoked during repaint, a new activity generates 2 MB of junk data, but the garbage collection mechanism does not collect it. If you play a video for about 30 minutes, the memory will be full and a crash will occur.