Calling varargs method without varargs parameter.

Hello
I really appreciate your help on clarifying the following problem.
1) I have method signature as
public User validateUser(User usr, boolean isLogin,Object...args)
2) When I call this method as
obj.validateUser(usrObject,true);
In windows environment, the method implementation specified in 1) is called and no issues.
But, when the same code is deployed on linux, I get the following error
java.lang.NoSuchMethodError: com.mysubpackage.dao.myobject.*validateUser(Lcom/startf orce/system/User;Z)Lcom/startforce/system/User;*
Please let me know, if there is any known incompatibility issue out there between windows and linux.
Thanks
Muthu

Hi Jverd
You are right! I think I worked too much and got lost somewhere, to prove me wrong I wrote the following test class and ran on both linux and windows and produced the same result (as it should). -:) Thanks all of you for responding.
public class VarArgsTest {
      * @param args
     public static void main(String[] args) {
           VarArgsTest test = new VarArgsTest();
           System.out.println("\nCalling varArgs with two parameter as test.printVarArgs(\"I am Param1 Value\", \"I am Param2 value\")");
           test.printVarArgs("I am Param1 Value", "I am Param2 value");
           System.out.println("Calling varArgs with three parameter as test.printVarArgs(\"I am Param1 Value\", \"I am Param2 value\", \"I am Param3 value\")");
           test.printVarArgs("I am Param1 Value", "I am Param2 value","I am Param2 value");
     public void printVarArgs(String param1, String param2, Object...objects) {
          System.out.println("\nparam1 = "+param1+"\nparam2 = "+param2);
          System.out.println();
          System.out.println(" param3 [Object...objects] length = "+objects.length);
          System.out.println();
          if(objects.length > 0)
               System.out.println("Param 3 is not empty and its first value is  = "+objects[0]);
          else
               System.out.println("Param 3 is  empty and nothing to display, it is an empty array ");
Output
Calling varArgs with two parameter as test.printVarArgs("I am Param1 Value", "I am Param2 value")
param1 = I am Param1 Value
param2 = I am Param2 value
param3 [Object...objects] length = 0
Param 3 is empty and nothing to display, it is an empty array
Calling varArgs with three parameter as test.printVarArgs("I am Param1 Value", "I am Param2 value", "I am Param3 value")
param1 = I am Param1 Value
param2 = I am Param2 value
param3 [Object...objects] length = 1
Param 3 is not empty and its first value is = I am Param2 value
Edited by: Startup_Muthu on Mar 12, 2008 11:41 AM
Edited by: Startup_Muthu on Mar 12, 2008 11:43 AM

Similar Messages

  • Using Java Reflection to call a method with int parameter

    Hi,
    Could someone please tell me how can i use the invoke() of the Method class to call an method wiht int parameter? The invoke() takes an array of Object, but I need to pass in an array of int.
    For example I have a setI(int i) in my class.
    Class[] INT_PARAMETER_TYPES = new Class[] {Integer.TYPE };
    Method method = targetClass.getMethod(methodName, INT_PARAMETER_TYPES);
    Object[] args = new Object[] {4}; // won't work, type mismatch
    int[] args = new int[] {4}; // won't work, type mismatch
    method.invoke(target, args);
    thanks for any help.

    Object[] args = new Object[] {4}; // won't work, type
    mismatchShould be:
        Object[] args = new Object[] { new Integer(4) };The relevant part of the JavaDoc for Method.invoke(): "If the corresponding formal parameter has a primitive type, an unwrapping conversion is attempted to convert the object value to a value of a primitive type. If this attempt fails, the invocation throws an IllegalArgumentException. "
    I suppose you could pass in any Number (eg, Double instead of Integer), but that's just speculation.

  • Dynamic Imagelink Component - Calling Impl method with input parameter

    Hi All,
    I have requirement where Imagelinks are created dynamically on the pageload. Generated the components and the components are displayed on the jspx.
    Now when I click the image link, a method in AMImpl should invoke and this method takes some input parameters.
    I am able to call the method successfully in AMimpl with the help of below code. But I could not understand how to pass the input parameters to that method.
                               RichCommandImageLink lockimageLink =
                                new RichCommandImageLink();
                            lockimageLink.setIcon("icon.png");
                            lockimageLink.setId("icon" + index);                   
                            MethodExpression me =
                                JSFUtils.getMethodExpression("#{bindings." +
                                                             "MyMethodName" +
                                                             ".execute}");
                            lockimageLink.addActionListener(new MethodExpressionActionListener(me));
      public static MethodExpression getMethodExpression(String name) { 
       Class [] argtypes = new Class[1]; 
       argtypes[0] = ActionEvent.class; 
       FacesContext facesCtx = FacesContext.getCurrentInstance(); 
       Application app = facesCtx.getApplication(); 
       ExpressionFactory elFactory = app.getExpressionFactory(); 
       ELContext elContext = facesCtx.getELContext(); 
       return elFactory.createMethodExpression(elContext,name,null,argtypes); 
      } Can some one please suggest how to pass input parameters to the Impl method.
    Jdeveloper Version : 11.1.1.4.0
    Thanks,
    Morgan.
    Edited by: 900114 on May 12, 2012 11:23 PM

    You can use the below method to call an AMImpl method. You can pass parameters as well to the AMImpl method.
    DCBindingContainer bindings = getDCBindingContainer();
    OperationBinding ob = bc.getOperationBinding("MyMethodName");
    Map m = ob.getParamsMap();
    ob.put("paramName", "paramValue"); paramName is the parameter in AMImpl and paramValue is the value to be passed.
    ob.execute();
    Where getDCBindingContainer() is:
    public DCBindingContainer getDCBindingContainer() {
    ExpressionFactory exprFactory;
    ELContext elContext;
    ValueExpression valueExpression;
    DCBindingContainer dcBindingContainer;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    exprFactory = facesContext.getApplication().getExpressionFactory();
    elContext = facesContext.getELContext();
    valueExpression =
    exprFactory.createValueExpression(elContext, "#{bindings}",
    Object.class);
    dcBindingContainer =
    (DCBindingContainer)valueExpression.getValue(elContext);
    return dcBindingContainer;
    Hope this helps
    Edited by: umesh.agarwal on May 13, 2012 12:10 AM
    Edited by: umesh.agarwal on May 13, 2012 12:10 AM

  • Newbie Q'n -- Calling class methods without instantiation

    Hello All,
    I would like to know how is it possible to call methods within a class without instatiating the class.
    For instance consider the following statement:
    String x = Integer.toString(10);
    Here there we are calling the toString() function of "Integer" class without instantiating it. How is it possible?? How does the JVM call the toString() function when there is no Integer object defined in my program?? Can the same functionality achieved for user created classes ??
    Can anyone explain ??
    If this appears as a trivial question, please forgive me.
    Thanks in advance,
    Arun

    String x = Integer.toString(10);
    Here there we are calling the toString() function of
    "Integer" class without instantiating it. How is it
    possible?? How does the JVM call the toString()
    function when there is no Integer object defined in my
    program?? Can the same functionality achieved for user
    created classes ?? It isn't possible, and its not happening in your example either:
    toString() is an instance method. toString(int) and toString(int, int) are class (static) methods.
    You might see documentation referring to a toString (notice no "()" at the end) method. When you do, it should usually be clear from the context which particular method is being referred to.
    Such confusion might well have been avoided if the original API designers had thought to call the methods something different (perhaps format?), but they didn't (in fact, toString(int) seems rather pointless).

  • How call native method without code modification

    "How to access third party's C API from Java Using JNI without modifying the C code"

    Unfortunately, the only way I know of doing this is to use a pass-through DLL that you write. Logically it
    looks like this:
    Java App (written by you)
    |
    v
    Java native methods (written by you)
    |
    v
    JNI DLL (written by you)
    |
    v
    3rd party DLL
    It adds a little bit of overhead, but it's not too big of a deal. Check out the JNI tutorial on how to write this.
    Bryan

  • Call a methode without opening the main view

    Hi,
    I have a function that calls a web dynpro application. The handledefault methode of the window from this web dynproapplication searches for a url of a picture and opens it with my browser.
    This works well.
    But there are two windows open: my picture and the empty web dynpro main view.
    How can I stop this? I just want the window with my picture.
    Thanks,
    Martina.

    Hi Manigandaan,
    I deleted  the empty main view from the webdynpro window.
    But the result is always the same:
    1 empty window and
    1 window with my url
    this is the code in the handledefault (after the data declaration):
    DATA lo_window_manager TYPE REF TO   if_wd_window_manager.
       DATA lo_api_component  TYPE REF TO   if_wd_component.
       DATA lo_window         TYPE REF TO   if_wd_window.
       DATA ld_url            TYPE          string.
       lo_api_component  = wd_comp_controller->wd_get_api( ).
       lo_window_manager = lo_api_component->get_window_manager( ).
    ld_url = lv_doclink.
      data lo_api_controller type ref to if_wd_view_controller.
      data lo_window_ctlr TYPE REF TO if_wd_window_controller.
      lo_api_controller = wd_this->wd_get_api( ).
      lo_window_ctlr = lo_api_controller->GET_EMBEDDING_WINDOW_CTLR( ).
    * get the control for window to be closed
      lo_window = lo_window_ctlr->get_window( ).
    * this will close the window
      lo_window->close( delete_window = abap_true ).
    if the ld_url is i.e. 'http://www.google.com' I get one browser window with google and another
    browser window which is empty. The URL of this empty browser window is the url with which
    i called the web dynpro application. But I don't need this window, how can I avoid this?
    Thank you very much!!!
    Martina

  • How to do this: Link which calls a methode with a parameter?

    Hello!
    I have a small question:
    I have a jsp-site with some beans.
    On the jsp-site I have the following code which isnt functional:
    <c:forEach items="${filter.resultlist}" var="result">
        <c:url action="#{filter.selectedAoid(result.aoid)}">
             <c:out value="${result.name}" / >
         </c:url>
    </c:forEach>-> As you can see:
    I want to make a Link, which is named like the String in the List and accessable by ${result.name} and on a click it should run "filter.selectedAoid()" with an int Parameter.
    (So I can access the right object with my Aoid-identifier...)
    The List comes from a DB and I am able to access the values of the Objects in the list.
    Could someone please tell me how that is done?
    Thanks in advance
    Fuchur

    One way of hacking this problem is by dynamically updating the job step which executes the stored procedure to include the parameters the user provided.  You can do so by using
    msdb.dbo.sp_update_jobstep.
    So for example, you could create a job named "Test job" and in that job the first step would be to execute your stored procedure.  You would then use the following code to update that step at run time:
    execute msdb.dbo.sp_update_jobstep
    @job_name = N'Test job',
    @step_id = 1,
    @command = 'execute my_proc @my_variable = ''my_value'''
    You'd then use sp_start_job like so:
    execute msdb.dbo.sp_start_job @job_name = 'Test job'
    Your job would then execute using the value provided at run time for the @my_variable parameter.

  • Problem calling a method which takes a parameter from a table

    Hi guys,
    I'm very new to jsf and hope you can help me out.
    On my page i'm generating a list, which is working fine. now i want to add some commandLinks to the list entries. on click, i want to execute a bean method, which takes a parameter from the list, generates a picture and displays it on my page.
    here's a piece of code thats already working:
    <rich:dataTable var="data" value="#{pathwayBean.orgList}">
    <rich:columnGroup>     
            <rich:column>     
               <h:outputText value="#{data.name}" />
         </rich:column>
    </rich:columnGroup>
    </rich:dataTable>now, i want to replace the outputText with a commandLink, and execute a method with {data.id} as parameter. Unfortunately, the commandLink property "action" can only call bean methods with no parameter, or is that wrong?
    Thanks in advance,
    Alex

    use actionlistener.
    here a typical code that works fine for me:
    (JSF 1.2)
    //Java
    private Integer selectedItemId=null;
         public void selectItem(ActionEvent event) {
              // Find the UIParameter component by expression
              UIParameter component = (UIParameter) event.getComponent().findComponent("itemId");
              // parse the value of the UIParameter component
              try {
                   selectedItemId = Integer.parseInt(component.getValue().toString());
                   // find itemBean here using selectedItemId
              } catch (Exception e) {
                   logger.error(e, e);
              logger.info(" +++ selectedItemId =" + selectedItemId);
         public String viewItem() {
                 //create view beans here
                 return "itemView";//return appropriate view.
    //JSF
    <h:column>
                             <h:commandLink     id="View"
                                                 action="#{itemListBean.viewItem}"
                                                       actionListener="#{itemListBean.selectItem}">
                                  <h:outputText value="select"/>
                                  <f:param id="itemId" name="itemId" value="#{itemBean.id}"/>
                             </h:commandLink>
                     </h:column>

  • Calling a method within an application?

    Hi I'm a student taking an intro Java class and right now I have to develop and application that prompts for someone to input a character of the alphabet and it will display the corresponding number on a telephone that it is listed under. The main method gets the input from the user and we are required to retrieve the corresponding digit to the character from a separate method using either a switch statement or a nested if-then-else statement to determine what the digit is. I'm having trouble calling that method in the main class which is another requirement. any suggestions?
    public class Hmwk08
         * Main driver begins program execution.
         * @param args program arguments
        public static void main(String[] args) throws Exception
            char letter;
            char ch;
            int relatesTo;
            PrintStream win = new PrintStream(System.out);
            Scanner in = new Scanner(System.in);
            String newLine = System.getProperty("line.separator");
            win.println("Given a letter of the alphabet, this program" + newLine
                        + "will tell you the corresponding digit on a" + newLine
                        + "telephone keypad.");
            win.println();
            win.print("Enter a letter: ");
            letter = in.nextLine().charAt(0);
            letter = Character.toUpperCase(letter);
         * Get the digit on a telephone keypad that corresponds
         * to the specified character. If the character is neither
         * a letter nor a digit, this method will retun the
         * asterisk character: '*'
         * @param letter the specified character
         * @return the corresponding digit
        private static char getPhoneDigit(char letter)
            char digit;
            digit = '*';
            if(letter == 'A' || letter == 'B' || letter == 'C')
                digit = '1';
            return digit;
    }

    Your method is static so you can call your method without creating a Hmwk08 object.
    char result = getPhoneDigit(letter);Would suffice in your main method
    Mel

  • Non-varargs call of varargs method with inexact argument type for last para

    i have no idea what the error:
    non-varargs call of varargs method with inexact argument type for last parameter
    means.
    return (Component)sceneClass.getConstructor(
    new Class[]{int.class, int.class}).newInstance(
         new Integer[]{new Integer((int)sceneDimension.getWidth()),
                new Integer((int)sceneDimension.getHeight())});
    this is the problem area but i'm not sure how to get around it..
    any help would be appreciated

    I am a Java learner and I got the same warning. My code runs like this:
    import java.lang.reflect.*;
    class Reflec
         public static void main(String[] args)
              if(args.length!=1)
                   return;
              try
                   Class c=Class.forName(args[0]);
                   Constructor[] cons=c.getDeclaredConstructors();
                   Class[] params=cons[0].getParameterTypes();
                   Object[] paramValues=new Object[params.length];
                   for(int i=0; i<params.length; i++)
                        if(params.isPrimitive())
                             paramValues[i]=new Integer(i+3);
                   Object o=cons[0].newInstance(paramValues);
                   Method[] ms=c.getDeclaredMethods();
                   ms[0].invoke(o, null);
              catch(Exception e)
                   e.printStackTrace();
    class Point
         static
              System.out.println("Point class file loaded and an object Point generated£¡");     
         int x, y;
         void output()
              System.out.println("x="+x+"\ny="+y);
         Point(int x, int y)
              this.x=x;
              this.y=y;
    When I compiled the file I got the following:
    Reflec.java:26: warning: non-varargs call of varargs method with inexact argument type for last parameter;
    cast to java.lang.Object for a varargs call
    cast to java.lang.Object[] for a non-varargs call and to suppress this warning
    ms[0].invoke(o, null);
    ^
    1 warning
    Since the problem was with this line "ms[0].invoke(o, null);" and the specific point falls on the last argument as the warning mentioned that " ... method with inexact argument type for last parameter", I simply deleted the argument "null" and the line becomes "ms[0].invoke(o);" and it works, no warning anymore!
    DJ Guo from Xanadu
    Edited by: Forget_Me_Not on Jan 8, 2009 10:39 AM

  • How to call a instance method without creating the instance of a class

    class ...EXCH_PRD_VERT_NN_MODEL definition
    public section.
      methods CONSTRUCTOR
        importing
          value(I_ALV_RECORDS) type ..../EXCH_VBEL_TT_ALV
          value(I_HEADER) type EDIDC .
      methods QUERY
        importing
          I_IDEX type FLAG
          i_..........
        returning
          value(R_RESULTS) type .../EXCH_VBEL_TT_ALV .
    Both methods are instance methods.
    But in my program i cannot created instance of the class unless i get the results from Query.
    I proposed that Query must be static, and once we get results we can create object of the class by pasing the result table which we get from method query.
    But i must not change the method Query to a static method.
    Is there any way out other than making method Query as static ?
    Regards.

    You can't execute any instance method without creating instance of the class.
    In your scenario, if you don't want to process your method of your class, you can check the instance has been created or not.
    Like:
    IF IT_QUERY IS NOT INITIAL.
      CRATE OBJECT O_QUERY EXPORTING......
    ENDIF.
    IF O_QUERY IS NOT INITIAL.
    CALL METHOD O_QUERY->QUERY EXPORTING....
    ENDIF.
    Regards,
    Naimesh Patel

  • I cann't call a method if it use HttpServletRequest as a parameter

              I use WebLogic5.1 as a WebServer.
              When I use javabean in a jsp file, everything is ok if call a method which don't
              use HttpServletRequest as parameter.But this method use HttpServletRequest as
              parameter, It cann't work.show this error:
              Error 500--Internal Server Error
              From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
              10.5.1 500 Internal Server Error
              The server encountered an unexpected condition which prevented it from fulfilling
              the request.
              what is this error mean?what can I do for it?
              

              I use WebLogic5.1 as a WebServer.
              When I use javabean in a jsp file, everything is ok if call a method which don't
              use HttpServletRequest as parameter.But this method use HttpServletRequest as
              parameter, It cann't work.show this error:
              Error 500--Internal Server Error
              From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
              10.5.1 500 Internal Server Error
              The server encountered an unexpected condition which prevented it from fulfilling
              the request.
              what is this error mean?what can I do for it?
              

  • Can we call a static method without mentioning the class name

    public class Stuff {
         public static final int MY_CONSTANT = 5;
         public static int doStuff(int x){ return (x++)*x;}
    import xcom.Stuff.*;
    import java.lang.System.out;
    class User {
       public static void main(String[] args){
       new User().go();
       void go(){out.println(doStuff(MY_CONSTANT));}
    }Will the above code compile?
    can be call a static method without mentioning the class name?

    Yes, why do it simply?
    pksingh79 wrote:
    call a static method without mentioning the class name?For a given value of   "without mentioning the class name".
        public static Object invokeStaticMethod(String className, String methodName, Object[] args) throws Exception {
            Class<?>[] types = new Class<?>[args.length];
            for(int i=0;i<args.length;++i) types[i] = args==null?Object.class:args[i].getClass();
    return Class.forName(className).getDeclaredMethod(methodName,types).invoke(null,args);

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

  • EL - How do you call a method that requires a parameter

    How do you call a method that requires a parameter
    In scriplet code here is what I am trying to do
    <%= car.getDefaultColor(car.getCarType()) %>
    How do I do this in EL
    Here is my guess (it generates the Exception described below)
    ${car.defaultColor(car.carType)}
    Here is the Exception I am getting:
    javax.servlet.ServletException: <h3>Validation error messages from tag library c</h3>tag = 'out' / attribute = 'value': An error occurred while parsing custom action attribute "value" with value "${car.defaultColor(car.carType)}": Encountered "(", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||"]
    Any Ideas?
    P.S. If it matters to you, I am using JSTL 1.0 and the code snippets above are actually within the value attribute of a <c:out value="" /> statement.

    How do you call a method that requires a parameter
    In scriplet code here is what I am trying to do
    <%= car.getDefaultColor(car.getCarType()) %>
    How do I do this in ELYou don't. EL is very strict in method signatures. All get methods must be public Type getProperty(void); And all set methods must be public void setProperty(Type t);
    So you will have to re-work your Bean so it does not need an argument to the get method (getDefaultColor()). Since you are calling another method out of car, you might re-write the getDefaultColor method as such:
      public Object getDefaultColor() {
        CarType ct = this.getCarType();
        //then do other stuff
      }If that isn't suitable, then provide a helper method that is used to set the current car type and then call the getDefaultColor:
      private CarType curCarType;
      public void setCurrentCarType(CarType ct) { curCarType = ct; }
      public Object getDefaultColor() {
        if (curCarType == null) throw new IllegalStateException("CarType must be set before getting color");
        //normal work using curCarType
    <c:set target="${car}" property="currentCarType" value="${car.carType}"/>
    <c:out value="${car.defaultColor}"/>It is better to do as little of the data manipulation (setting up the car type) in the JSP as possible, so the first option is better than the second. Also better then the second would be to set the current car type in a servlet or data access object (or wherever) from which your retreive the car to begin with. Manipulatig it in the JSP itself should be your last resort (to keep as much business logic out of the JSP as possible).
    Here is my guess (it generates the Exception
    described below)
    ${car.defaultColor(car.carType)}
    Here is the Exception I am getting:
    javax.servlet.ServletException: <h3>Validation error
    messages from tag library c</h3>tag = 'out' /
    attribute = 'value': An error occurred while parsing
    custom action attribute "value" with value
    "${car.defaultColor(car.carType)}": Encountered "(",
    expected one of ["}", ".", ">", "gt", "<", "lt",
    "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[",
    "+", "-", "*", "/", "div", "%", "mod", "and", "&&",
    "or", "||"]
    Any Ideas?
    P.S. If it matters to you, I am using JSTL 1.0 and
    the code snippets above are actually within the value
    attribute of a <c:out value="" /> statement.

Maybe you are looking for

  • HT2534 Best practice in setting up an iTunes Connect account for my business

    I have a personal iTunes account but I want to create a separate business account so that I can sign up for iTunes Connect to create books? Any suggestions? Should I create a new iTune account or not. I would like to keep them separate but I don't ne

  • Is VLC ok after the latest upgrade?

    hi~ cuz i didnt find anything, i am posting it here... Anyone of u having problems with VLC after the latest upgrades? (QT, iTunes, system upgrade) thanks....

  • Message from AQ to Workflow

    Hi, I am enqueueing messages to 'WF_IN' using dbms_aq.enqueue(). I have a subscriber defined on WF_IN using dbms_aqadm.add_subscriber(). I can see the messages in the 'ready state' thru WF monitor. Now I want to receive this message in Workflow. Step

  • Case type Default data

    Hello Team, In the case type default data in GTS for the Procedure CMCD - Customs document, system asks below fields Foreign trade Organization Document Type Goods Direction for SPL and Embargo check in customs document, i wanted to determine seperat

  • Still can't install Flash on IE8!

    Hey everyone... I've tried every fix on the internet for my brand new HP Envy to get Flash installed. I'm out of luck. Can anyone help me with additional support? Thank you!!