mercredi 10 janvier 2018

Reflection API not invoking the methods defines in invoked method in Java Spring

i am invoking a method dynamically which call some more methods.

    try {
            Class<?> jobClass = Class.forName(job.getClassName());
            System.out.println(jobClass.getName());
            Object jobObject = jobClass.newInstance();

            Method jobfunction=
jobObject.getClass().getMethod(job.getFunctionName());
            /*FastClass jobMethod = FastClass.create(jobClass).getMethod(job.getFunctionName());*/
            jobfunction.setAccessible(true);
            jobfunction.invoke(jobObject);

            }catch(Exception e) {
                System.out.println(e.toString());
            }

the above is returning null pointer exception when invoked method calls the method on any other class.

i.e if i am invoking a method 1 of class A and method 1 is calling method 2 of class B it gives null exception.how to solve this dynamically?





Aucun commentaire:

Enregistrer un commentaire