ClassnotFound exception using java reflection

前端 未结 2 724

i am trying to gt a list of method on a particular java class object i have created and trying to unit test it.

It fails saying it cannot find the class with a \"jav

相关标签:
2条回答
  • 2020-12-22 13:10

    The toString of the Class class returns: "class com.foo.NameOfClass" So it is trying to load: class com.jr.freedom.user.User (as your error messages states)

    But more importantly, you already have the class: User.class, why try to load again? Just take that line out and have:

    User.class.getDeclaredMethods...
    
    0 讨论(0)
  • 2020-12-22 13:13

    The result of User.class.toString() is:

    class com.jr.freedom.user.User
    

    See the class before the real classname starts? That makes the string an illegal class name.

    You need to use getName().

    0 讨论(0)
提交回复
热议问题