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

[1744 byte] By [tonyOne909a] at [2007-10-1 1:24:12]
# 1

I think the problem is with the line where you actually perform the invocation:

Value myValue= obj.invokeMethod(event.thread(), emptyState, null,ObjectReference.INVOKE_SINGLE_THREADED);

You really can't just pass null to indicate that your argument list should be empty. Try doing something like:

Value myValue= obj.invokeMethod(event.thread(), emptyState, new ArrayList() ,ObjectReference.INVOKE_SINGLE_THREADED);

And check if it works. Another healthy habit would be to check that the list returned by methodsByName actually contains something (but I think you're just playing around, right?).

Cheers,

Giuliano

gmega@terra.com.bra at 2007-7-8 1:43:55 > top of Java-index,Archived Forums,Debugging Tools and Techniques...