[Android] Solution to error java.lang.reflect.InvocationTargetException

Error message: java.lang.reflect.InvocationTargetException The reflection layer failed to call the method.

Result graph

Insert image description here

reason

InvocationTargetException exception is thrown by the Method.invoke(obj, args…) method. (Reflection exception)
When an exception is thrown inside the called method but is not caught, this exception will be received! ! !
The reflection layer wraps all exceptions in an InvocationTargetException, which allows you to distinguish whether the exception is actually a call failure caused by the reflection layer (such as an invalid parameter list) and an error within the calling method.

The situation I encountered was: activityView.printQuantityStatistics.setText(printNum); printnum is of int type, so I put it in directly, and the code did not report an error. However, when running, it crashed. I suspected there was a problem here, so I changed it. The code here, activityView.printQuantityStatistics.setText(String.valueOf(printNum) );
runs successfully

Solution

1. Check whether the invoke parameters are consistent with the parameters of the calling method.
2. Check the parameter types of the calling method.

Guess you like

Origin blog.csdn.net/KJJfighting/article/details/131761827