my dog learned polymorphism
The moose likes Java in General and the fly likes NoSuchMethodException for java.lang.Class.setValue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "NoSuchMethodException for java.lang.Class.setValue" Watch "NoSuchMethodException for java.lang.Class.setValue" New topic
Author

NoSuchMethodException for java.lang.Class.setValue

Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 78
Hi,
I am getting the following error when I am trying to excute the below code. I am not able to understand what is causing the below error, I felt its a jar file problem but not able to find the exact jar file.


public static Object invokeMethod(Object p_object,String p_method,Object p_value)
throws Exception {
Method l_method = null;
Object[] l_params = null;
Class[] l_paramTypes = null;
Object l_resultObject = null;
GEALogger.dbg(_moduleName,"invoking method "+p_method+" on "+p_object.getClass().toString());
try {
if(p_value != null){
l_paramTypes = new Class[] { p_value.getClass() };
l_params = new Object[] { p_value };
}
l_method = p_object.getClass().getMethod(p_method,l_paramTypes);
l_resultObject = l_method.invoke(p_object,l_params);
}catch(Exception p_excep){
GEALogger.dbg(_moduleName,"Method "+p_method+" not found in class "+p_object.getClass().getName());
throw p_excep;
}
return l_resultObject;
}

java.lang.NoSuchMethodException: java.lang.Class.setValue(com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl)
at java.lang.Class.getMethod(Class.java:1581)
at com.ge.industrial.gdsn.messaging.batch.file.xml.req.MethodInvoker.invokeMethod(MethodInvoker.java:32)
at com.ge.industrial.gdsn.messaging.batch.file.xml.req.RequestCreator.addToRequest(RequestCreator.java:166)
at com.ge.industrial.gdsn.messaging.batch.file.xml.req.XMLItemCreator.addElement(XMLItemCreator.java:191)
at com.ge.industrial.gdsn.messaging.batch.file.xml.req.XMLItemCreator.createXMLFile(XMLItemCreator.java:140)
at com.ge.industrial.gdsn.messaging.manager.ItemManager.createItemXMLFile(ItemManager.java:331)
at com.ge.industrial.gdsn.messaging.batch.ItemProducer.produceItems(ItemProducer.java:58)
at com.ge.industrial.gdsn.messaging.batch.ItemProducer.start(ItemProducer.java:40)
at com.ge.industrial.gdsn.messaging.batch.GDSNDataPoolInterface.main(GDSNDataPoolInterface.java:53)



regards
Prashanth
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 125
Is your class is implementing java.lang.reflect.InvocationHandler interface. If yes then below method signature for invoking any method,

public Object invoke(Object proxy, Method m, Object[] args)

Red marked should be array of object not object.

Hope this will be helpful.

Sunil
Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 78
Hi
My class is using the following class: java.lang.reflect.Method. Its not importing/implementing any other classes.



regards
Prashanth
Rajneesh K Rajput
Greenhorn

Joined: Nov 14, 2009
Posts: 10
java.lang.NoSuchMethodException: java.lang.Class.setValue(com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl) almost clarily explaining the problem is with below lines.






  • This could be problem with the dynamic method call, because it does not exists in the jar version which is currently in use.


  • Please verify at run time, all required prerequisits i.e. class name, method name and parameter list are correct and in order as required.


    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19216

    The exception says it all: You are trying to call setValue(com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl) but the method is probably setValue(java.util.Calendar).

    You could try the following:
    - list all methods
    - if the name is setValue check the parameter types
    - if the parameter type allows the argument (use Class.isInstance) take that method and abort


    SCJP 1.4 - SCJP 6 - SCWCD 5
    How To Ask Questions How To Answer Questions
    Prashanth Chandra
    Ranch Hand

    Joined: Dec 07, 2005
    Posts: 78
    Hi,
    I have tried the above options but these does not seem to solve my problem,can someone help me in understading where exactly the issue is/which jar file is creating this issue. I have a lot of jar files in my application because of which I am not able to understand which jar version is going wrong. I have tried with the below jars by downloading the latest one which did not sovle by problem.

    xercesImpl.jar
    jaxp.jar
    xml-apis.jar

    regards
    Prashanth
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19216

    I have told you, you are trying to call the wrong method.

    Consider the following example:
    The invokeMethod method should try to find setValue(Object), but because you are using the actual run time class to look for the method, the invokeMethod method actually tries to find setValue(String). It can't find one so it fails.

    Also, my suggestion was not three suggestions but one single suggestion. In pseudo code (only line 15 needs to be filled in):
     
    I agree. Here's the link: http://zeroturnaround.com/jrebel/download
     
    subject: NoSuchMethodException for java.lang.Class.setValue
     
    Similar Threads
    Can some one help me out with this code..
    Need a disconnected resultset
    Sending class file through a network
    dont know where the problem is... after loading... please help me out....
    reading file from jar - Problem