how to invokemethod in ObjecReference JDI
Hi I need some help with the invokeMethod in objectReference class. How do you use it ? I Here is my sample code
public void methodExitEvent(MethodExitEvent event)
{
ObjectReference obj = objectReference(event);
if(obj!=null && !event.method().name().equals("<init>"))
{
System.out.println(" Leaving the method " + event.method().name() + "() Object " + obj.hashCode());
List objMethodsList =event.method().declaringType().methodsByName("methodA");
Method emptyState= (Method)objMethodsList.get(0);
//ClassType myClass= (ClassType)obj.referenceType();
//Method emptyState= myClass.concreteMethodByName("methodA","()V");
try
{
Value myValue= obj.invokeMethod(event.thread(), emptyState ,null,ObjectReference.INVOKE_SINGLE_THREADED);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error in invoking method "+e.getMessage());
}
}
else if(obj!=null && event.method().name().equals("<init>"))
System.out.println("Object " + obj.hashCode()+" END its life");
}
The thing is when the invokeMethod is called it gives me a null pointer exception. I just dont get it how is this so. Below is the stack trace produced from the excetion thrown.
java.lang.NullPointerException
at com.sun.tools.jdi.MirrorImpl.validateMirrorsOrNulls(MirrorImpl.java:8
2)
at com.sun.tools.jdi.ObjectReferenceImpl.invokeMethod(ObjectReferenceImp
l.java:355)
at EventThread.methodExitEvent(EventThread.java:186)
at EventThread.handleEvent(EventThread.java:69)
at EventThread.run(EventThread.java:35)
Error in invoking method null

