Getting java.lang.NullPointerException when calling Method.invoke

前端 未结 4 1214
耶瑟儿~
耶瑟儿~ 2021-02-19 11:17

I\'m following this tutorial on Java annotaitons and implemented the Test annotation as shown there. But when running the code I get the following output.

java.l         


        
4条回答
  •  情歌与酒
    2021-02-19 11:47

    The problem is that you are passing a null target object to method.invoke(object) method. The target object should not be null, else a nullpointerexception is expected.

    The invoke method has below usages:

    Method.invoke(targetObject, args1, args2, args3...); where args1, args2, args3 etc are argument to the method being invoked.

提交回复
热议问题