Problems with String[] Class Object

Hi guys,
I'm writing a web server who should invoke a method of a class when asked by a client.
My problem is that if the method that should be invoked has a String[] parameter the web server is unable to invoke it and throws a java.lang.IllegalArgumentException: argument type mismatch.
Useful pieces of code to understand are the following:
//create the Class[] to pass as parameter to the getMethod method
Class[] paramType = {String[].class};
//find the class "className" and create a new instance
Class c = Class.forName(className);
Object obj = c.newInstance();
//the getMethod should find in the class c the method called nameMeth
// having paramType (i.e. String[]) as parameter type...
Method theMethod = c.getMethod(nameMeth, paramType);
//here's the problematic call!!
theMethod.invoke(obj, params);I've noted that System.out.println(theMethod); prints the signature of the method with the parameter type java.lang.String[].
System.out.println(paramType[0]); instead prints [Ljava.lang.String;
I know that [L means that it is an array, so why do you think that I'm having an argument type mismatch?
Thank you                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

I had no problems making that work.import java.lang.reflect.Method;
public final class StringArray {
    public static final String CLASSNAME = "StringArray";
    public static final String METHODNAME = "myMethod";
    public static final String[] sa = { "a", "b"};
    // automatic no-args constructor
    public final void myMethod(String[] sa) {
        for(int i=0;i<sa.length;++i) {
            System.out.println(sa);
public static final void main(String[] arg) throws Exception {
//create the Class[] to pass as parameter to the getMethod method
Object[] params = { sa };
Class[] paramType = {sa.getClass()};
//find the class "className" and create a new instance
Class c = Class.forName(CLASSNAME);
Object obj = c.newInstance();
//the getMethod should find in the class c the method called nameMeth
// having paramType (i.e. String[]) as parameter type...
Method theMethod = c.getMethod(METHODNAME, paramType);
//here's the problematic call!!
theMethod.invoke(obj, params);

Similar Messages

  • Getting problem with DOMImplementation classes method getFeature() method

    hi
    getting problem with DOMImplementation classes method getFeature() method
    Error is cannot find symbol getFeature()
    code snippet is like...
    private void saveXml(Document document, String path) throws IOException {
    DOMImplementation implementation = document.getImplementation();
    DOMImplementationLS implementationLS = (DOMImplementationLS) (implementation.getFeature("LS", "3.0"));
    LSSerializer serializer = implementationLS.createLSSerializer();
    LSOutput output = implementationLS.createLSOutput();
    FileOutputStream stream = new FileOutputStream(path);
    output.setByteStream(stream);
    serializer.write(document, output);
    stream.close();
    problem with getFeature() method

    You are probably using an implementation of DOM which does not implement DOM level-3.

  • Problems with inner classes in JasminXT

    I hava problems with inner classes in JasminXT.
    I wrote:
    ;This is outer class
    .source Outer.j
    .class Outer
    .super SomeSuperClass
    .method public createrInnerClass()V
         .limit stack 10
         .limit locals 10
         ;create a Inner object
         new Outer$Inner
         dup
         invokenonvirtual Outer$Inner/<init>(LOuter;)V
         ;test function must print a Outer class name
         invokevirtual Outer$Inner/testFunction ()V
    .end method
    ;This is inner class
    .source Outer$Inner.j
    .class Outer$Inner
    .super java/lang/Object
    .field final this$0 LOuter;
    ;contructor
    .method pubilc <init>(LOuter;)V
         .limit stack 10
         .limit locals 10
         aload_0
         invokenonvirtual Object/<init>()V
         aload_0
         aload_1
         putfield Inner$Outer/this$0 LOuter;
         return
    .end method
    ;test
    .method public testFunction ()V
         .limit stack 10
         .limit locals 10
         ;get out object
         getstatic java/io/PrintStream/out  java/io/PrintStream;
         aload_0
         invokevirtual java/lang/Object/getClass()java/lang/Class;
         ;now in stack Outer$Inner class
         invokevirtual java/Class/getDeclaringClass()java/lang/Class;
         ;but now in stack null
         invokevirtual java/io/PrintStream/print (Ljava/lang/Object;)V
    .end methodI used dejasmin. Code was equal.
    What I have to do? Why getDeclatingClass () returns null, but in dejasmin code
    it returns Outer class?

    Outer$Inner naming convention is not used by JVM to get declaring class.
    You need to have proper InnerClasses attribute (refer to http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#79996)
    in the generated classes. Did you check using jclasslib or another class file viewer and verified that your .class files have proper InnerClasses attribute?

  • Problem with database schema objects in the entity object wizard

    Hi All,
    When creating a new entity object, I am facing a problem with database schema objects in the entity object wizard, database schema objects (check boxes for tables,synonyms...) are disabled. Actually I am using a synonym but I am not able to select the synonym check box.
    Can any of you folks tell me how to enable the database schema objects (check boxes for tables,synonyms...).
    Thanks in Advance.
    Raja.M

    Make sure your using rite version of jdeveloper..
    Make sure your using apps schema and check whether your able perform DML operations in the schema vis sql developer.
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                           

  • Problem with String variable

    I am new to Java Programming.
    I have a line of code that works and does what is supposed to.
    faceData.getProfile("Lisa").removeFriend("Curtis");
    If I assign the strings to variables such as-
    String name = "Lisa";
    String fName = "Curtis";
    and then plug those into the same line of code, it does not work
    faceData.getProfile(name).removeFriend(fName);
    What could be causing the problem?
    I even added some lines to print out what is stored in the variables to verify that they are what they should be, but for some reason the variables do not work while putting the strings in quotes does. Any ideas?

    I guarantee that something about your assertions are incorrect. Those variables are either not equal to the values you claim, or something else is going on. But it's not a problem with string variables versus string constants.
    Edit: My best guess in lack of a real example from you, is that the strings in question have non-printable characters in them, such as trailing spaces or line feeds.

  • Little problem with Strings.

              I have an little problem with Strings, i make one comparision like this.
              String nombre="Javier";
              if( nombre.equalsIgnoreCase(output.getStringValue("CN_NOMBRESf",null)) )
              Wich output.getStringValue("CN_NOMBRESf",null) is "Javier" too, because I display
              this before and are equals.
              What I do wrong?.
              

    You are actually making your users key in things like
    "\026"? Not very user-friendly, I would say. But
    assuming that is the best way for you to get your
    input, or if it's just you doing the input, the way to
    change that 4-character string into the single
    character that Java represents by '\026', you would
    use a bit of code like this:char encoded =
    (char)Integer.parseInt(substring(inputString, 1),
    16);
    DrClap has the right idea, except '\026' is octal, not hex. So change the radix from 16 to 8. Unicode is usually represented like '\u002A'. So it looks like you want:String s = "\\077";
    System.out.println((char)Integer.parseInt(s.substring(1), 8));Now all you have to do is parse through the String and replace them, which I think shouldn't be too hard for you now :)

  • Facing lot of problems with the DATA object  -- Urgent

    Hi,
    I am facing lot of problems with the data object in VC.
    1. I created the RFC initially and then imported the data object in to VC. Later i did some modifications to RFC Function module,and when i reload the data object, I am not able to see the new changes done to RFC in VC.
    2. Even if i delete the function module, after redeploying the IVIew, results are getting displayed.
    3. How stable is the VC?
      I restarted the sql server and portal connection to R3 is also made afresh.... still i am viewing such surprise results..
    please let me know what might be the problem.

    Hi Lior,
    Are u aware of this problem.
    If yes, please let me know...
    Thanks,
    Manjunatha.T.S

  • Problem with Copied Business Object : SELFITEM

    Hi,
    sub:    Problem with Copied Business Object : SELFITEM
    I want to use changed selfitem BOR for carbon copy functionality. For it, i copied the BOR : SELFITEM. it is giving error
    In SWI2_DIAG it is showing like this.
    Work item  cannot be read                                                
    Work item 000000639770: Object  method SWW_BI_EXECUTE_S cannot be executed
    The problem is with COPYING The Business Object. Because , generally we extend BOR ,not copy. But i did copy.
    Please help me regarding this.
    Balaji.T.

    hi Martin,
    The problem may not be in method. because simply we copied the BO:SELFITEM into ZSELF . And i want to test this for a mail at first , whether copied BOR  is working or not.The mail is not triggering . it is saying that it is Error.
    WF_BATCH error...
    I can see error in Tx: SWI2_DIAG ,
    this is Error :
    Work item 000000639770: Object  method SWW_BI_EXECUTE_S cannot be executed
    Once it is rectified i can modify the method in BO:ZSELF.
    Thank you in Advance..
    Balaji.T.

  • Problem with String to Int conversion

    Dear Friends,
    Problem with String to Int conversion
    I am having a column where most of the values are numeric. Only 4 values are non numeric.
    I have replaces those non numeric values to numeric in order to maintain the data type.
    CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END
    This comes the result as down
    Grade
    _0_
    _1_
    _10_
    _11_
    _12_
    _13_
    _14_
    _15_
    _16_
    _17_
    _18_
    _19_
    _2_
    _20_
    _21_
    _22_
    _23_
    _24_
    _3_
    _4_
    _5_
    _6_
    _7_
    _8_
    _9_
    Refresh
    Now I want to convert this value to numeric and do some calculation
    So I changed the formula as below
    cast (CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END as INT)
    Now I get the following error
    View Display Error
    _     Odbc driver returned an error (SQLExecDirectW)._
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    _State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1722, message: ORA-01722: invalid number at OCI call OCIStmtFetch. [nQSError: 17012] Bulk fetch failed. (HY000)_
    SQL Issued: SELECT cast ( CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as Int) saw0 FROM "Human Capital - Manpower Costing" WHERE LENGTH(CASE Grade.Grade WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN 'E4' THEN '23' ELSE Grade.Grade END) > 0 ORDER BY saw_0_
    Refresh
    Could anybody help me
    Regards
    Mustafa
    Edited by: Musnet on Jun 29, 2010 5:42 AM
    Edited by: Musnet on Jun 29, 2010 6:48 AM

    Dear Kart,
    This give me another hint, Yes you are right. There was one row which returns neither blank nor any value.
    I have done the code like following and it works fine
    Thanks again for your support
    Regards
    Code: cast (CASE (CASE WHEN Length(Grade.Grade)=0 THEN '--' ELSE Grade.Grade END) WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' when '--' then '-1' ELSE Grade.Grade END as Int)

  • OWB ERROR:  created with second class object failure

    I'm getting this error when I import a table into the repository. any ideas?
    created with second class object failure

    Hello!
    Second class objects are columns, indexes, constraints etc. Probably some of these contains reserved OWB keywords. You can check what went wrong by drilling down to these objects on the results screen.
    Regards,
    Robert

  • Doubt with String class

    Please tell me why String class objects are immutable. Why it was designed like that?

    Read Java tutorials.Thanks for your reply. But tutorial says thatString
    objects are immutable but they dont say why
    they
    made
    as immutable.Welcome swathi.reply #4 is the best answer Ithink.
    But please look at my reply #8Please look at reply#2 in the other thread.But reply #2 was mine. I dont understand what you say? Please help me.

  • StringTokenizer class problem with strings in double quotes

    Hello Technocrats,
    I have a problem with tokenizing following string enclosed in (). (abc," India, Asia", computer engineer). My separator is ",", thus StringTokenizer class gives me 4 tokens namely abc, "India, Asia" and computer engineer. But I require that String in double quotes should be a single token. How to achieve this using StringTokenizer class? Or is there any other way?
    Thanks in advance.

    Try
    String[] str="abc,\" India, Asia\",computer engineer".split(",",1);
              for(String s: str)
                   System.out.println(s);
              }Thanks.

  • Problems with I/O object to a File

    First of all, hi to everybody, sorry for my English.
    I have a problem with my Exam Project. I need to write and read object (Utente) from a file. Following the Class then a Description of the Error/problem
    questo � il loader
    import java.io.*;
    public class Load {
    public Load(){}
    public void Caricalista(ListKey Lista) throws Exception{
    Utente loaded,x;
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream ("elenco.sav"));
    while((loaded = (Utente)ois.readObject())!=null){
    loaded = (Utente)ois.readObject();
    System.out.println(loaded.nome);
    Lista.insert(loaded);
    x=Lista.head();
    System.out.println(x.nome);}
    ois.close();
    Questo il Saver
    import java.io.*;
    public class Salva {
    public Salva(){}
    public void salva (Utente piero) throws IOException{
    Load loader=new Load();
    ListKey Lista=new ListKey();
    try{ loader.Caricalista(Lista);
    }catch (Exception e){System.out.println ("Errore in Salva.java");}
    FileOutputStream fos = new FileOutputStream ("elenco.sav");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    Lista.insert(piero);
    Utente test=new Utente();
    int i;
    for(i=0;i<Lista.lenght();i++){
    Lista.scorri(test);
    oos.writeObject(test);
    oos.close();
    public class ListKey extends ListNode {
    public ListKey() {super();}
    public ListKey (Utente o){super(o);}
    public ListKey(Utente o, List l){super (o,l);}
    public Utente find (String user){if (isEmpty())return null;
    if (user.equals(head().nome)) return head();
    return ((ListKey)tail()).find(user);
    public Utente scorri(Utente prova){if (isEmpty()) return null;
    else {prova=head();
    return ((ListKey)tail()).scorri(prova);
    e il main:
    public class mainvia {
    * @param args
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Utente prova=new Utente();
    prova.nome="Tettone";
    prova.psw="300786";
    prova.LibriPrestito="SI";
    prova.TitlePrestito1="IL Giovane Holden";
    ListKey Lista=new ListKey();
    Salva save=new Salva();
    try {save.salva(prova);}catch(Exception e){}
    Load loader=new Load();
    try{loader.Caricalista(Lista);
    }catch(Exception e){}
    Utente x=new Utente();
    System.out.println(x.nome);
    The problem is that, if I use only the Load for open the file,it works great and find the first User, instead if in the Salva I run try{ loader.Caricalista(Lista);
    }catch (Exception e){System.out.println ("Errore in Salva.java");}
    it always goes in Error and print "Errore in Salva.java" like if it can not open the file.
    How Can I Resolve?
    The base idea is the:
    from the mainvia I pass the ListKey Lista to save, then i load all the object from the file to the Lista, then i add to the List the new Object then i write all the object in the List to the file.

    Let's start by printing some useful information about the error, instead of just the fact that an error occurred:}catch (Exception e){e.printStackTrace();}Tell us what that produces.

  • Help - problems with mixin class and recursion

    I'm trying to set up functionality which will allow me to track gui node nesting.
    Basically, I'd like to have an optional name for each node and be able to generate a string which uses these to track descent. So, e.g., if I have "panel1" as my top scene, "control1" as a node within that scene and "image1" as a node within control1, I'd like to be able to produce the string "panel1.control1.image1" with a call to the image1 node.
    I am attempting to do this with a mixin class, as it seems precisely the sort of situation suited to mixins. So I have:
    import java.lang*;
    public mixin class Descent {
        public-init var objName:String = getClass().toString();
        public function getObjDescent():String;
    }When an object is created, it can be assigned a name - or, if there's no assignment, it gets given its class name. When I want the full "descent name" of the object, I'll call getObjDescent(). So far so good.
    But now it gets trickier. The idea is to track descent within javafx nodes. If I don't want to assume everything is set up properly, I've got to cover a few cases:
    (a) the class into which this object is mixed - the mixee - is not a javafx node
    (b) the mixee is a javafx node, but its parent is not
    (c) the mixee is a javafx node and descends from a javafx node
    Thus:
        public function getObjDescent():String
            var build:String="";
            // get parent's name, if it has it
            try {
                var nodeClass:Class[] = [javafx.scene.Node.class];
                var checkIsNode = this.getClass().getMethod("getNodeMaxHeight",nodeClass);
                if ((this as Node).parent != null) {
                    var parentDescentFn = (this as Node).parent.getClass().getMethod("getObjDescent",(null as Class[])) ;
                    build = ((this as Node).parent as Descent).getObjDescent();
                    build = build.concat(".");
            catch (e:NoSuchMethodException)
                build = "";
            build.concat(this.objName);
        };First I have to check if the mixee is a javafx Node. I can't do this by member checking because javafx doesn't support that. So I have to check by methods. I use one of the Node methods - getNodeMaxHeight - if it is defined for the mixee, the mixee is a node. If not, I'll get an error and can abort down to the catch section.
    If this mixee is a node, then it will have a parent node. If that parent also has descent info, I have to prefix that parent's descent name. So now I need to figure out if I can recursively call getObjDescent() on the parent.
    So I do the same getMethod() approach on the parent (if any) to see if it has a name I have to prefix. If not then, again, we abort out to the NoSuchMethodException error catch.
    Now I should be sure that this is a node and its parent has the Descent fields. So I should be safe to call the parent for its info.
    Here I've done this as
    ((this as Node).parent as Descent).getObjDescent().Though that gives me no errors, I'm not sure if that's the right way to cast things - will it look at the wrong portion of the object to find the method call? Better would be to call the function using the parentDescentFn variable, which I've gotten in checking to see if the parent has the Descent class mixed in, but I can't figure out how to go from a java.lang.reflect.Method variable to generating an actual call of that method. So there's a first question.
    However I get to that recursive call, I will get back the parent's descent name. I add my descent separator, '.', and then append the objName of this particular class. Voila - the full descent name.
    Though the above throws no warnings in the editor, it generates two compile errors.
    First, it tells me it cannot find the symbol:
    symbol  : method get$class()
    location: class javafx.scene.Node
                var nodeClass:Class[] = [javafx.scene.Node.class];I need to construct a Class[] containing Node for my call to getMethod in the next line. Is this not the right way to specify the Node class?
    The next error is:
    non-static variable this cannot be referenced from a static context
                var checkIsNode = this.getClass().getMethod("getNodeMaxHeight",nodeClass);I still find what javafx treats as "static" and what non-static to be mystifying. I'm fairly sure I've seen mixin classes which use "this" to grab the mixee object, and I certainly need to do so in this case to check if the mixee is a javafx Node and, subsequently, to get its parent Node.
    So... three problems:
    - Using "this" in a mixin class ... what's messing that up?
    - constructing the Class[] sequence for the first call to getMethod
    - (possibly) properly generating a call to the parent mixee's getObjDescent() method.
    urg.

    RE static vs non-static of this:
    I'm not sure, but I think it's a little less straightforward:
    e.g. if I type:
    var dummy = this; no problem. (This is analogous to what you did.)
    But if I type:
    var dummy = this.getClass();I get the static/non-static error. I take this to reflect the fact that getClass() is not defined by the mixin class, even if it is defined for any object which might use that class. (Perhaps, down deep in the code, "this" has been redirected to point just to that block of memory which gives the implementation of the mixin information?)
    Yet if I type
    var dummy = getClass();it works fine, and returns the class which is implementing the mixin.
    My guess is that "this" is being treated specially with a mixin class - I think, at compile time, if it just says "this" it is ignored by the "mixin" handling and passed along to the regular class compiling to process, but if it is this.method() or this.member, then the mixin class handles it and will throw that error if it gets any methods or members which it did not itself define.
    I haven't had any trouble using the Class objects in javafx, though I don't think I can easily make them do what I, here, specificly want to do. But getClass() seems to work just fine (as long as I don't say this.getClass() !!), as do calls to get or invoke members - I got that one of the 3 problems solved.
    I discovered that javafx seems to flatten its classes out to the single implementation of FXObject - when I attempted to parse the interfaces of the mixee class to see if "Node" was a member (which it should be, conceptually), I only got 2 interfaces: FXObject and my mixin class. So I can't use the Class commands to find out of the mixee class object implements Node or not.
    I also discovered that, given how javafx seems to compile itself into java, I could actually check for members as well as methods: getMethod("loc$parent") would actually return the parent member, if present. So getMethod can be used to check for the presence of both members and methods in javafx classes. I could not figure out, however, how to get from that reference to the value of the object itself - while invoke() works properly for methods, I couldn't get it to work for the members it retrieved. Though I didn't try too terribly hard.
    The getMethod() Class function did allow me to check if a class had my mixin class present - or, at least, if it contained a method with the same name as one defined in that class.
    Ultimately, though, I'm still stuck with trying to answer the questions, given a generic javafx class (implicit in this, which I could get by getClass()):
    - does this mixee class implement Node?
    - if so, what is the value of its "parent" member ((this as Node).parent didn't seem to work within the mixin class' code. Or so it seemed.)
    I've gotten around that problem by adding a Node member to the class, so that, rather than trying to deduce it from "this" or the Class functions, it simply uses its variable. Less elegant and more memory-using, but quicker and, actually, more flexible. That approach solves my immediate problem, though it does leave unanswered the more basic questions raised by the exercise.
    thanks for the feedback!

  • Problem with JFrame class.

    To risolve my problem i need for few diferent frame
    ( for esample in one i put JTextFild that take the user input, in a nother one i need for program output ) . But, th problem is, all my frames using the same object.
    If i construct diferent JFrame window class i have problem that i don't acess in the same object from all the window. And if i dont use a object, i have static acess .
    I risolve the problem with 1 JFrame class with diferent constructors, but i wont a diferent way to risolve my problem, because there are few windows.
    Help me.....

    Make the class that extends JFrame an inner class of the the main class. You can then access all members of the outer class.

Maybe you are looking for

  • Ethernet connection very slow

    Hello! I have a printer connected to the Extreme Base on the Ethernet port, and it's EXTREMELY slow, a 10 MB PDF file takes over 2 hours to transfer. The printers ethernet card runs @ 100 Mbps. The internet connection is just fine, the multicast rate

  • Hdv to compressor for web

    I am trying to put some footage on the web that i shot in hdv and compressor has many settings that are squeezing my image and not keeping it hdv. any suggestions? thanks, jim

  • HT204053 changing your apple id in icloud

    I changed my apple id and now I can't change my iCloud id, and can't access iCloud because my apple id is changed.  How do I chang my id in iCloud?

  • Audio Levels

    I now I can boost the audio levels in the timeline but what is a good range for the recorded audio levels when they first come in to FCP ? I have footage that's coming in at -2.4 dbs and peaking a little above that and under -1.8 I assume this is low

  • Create multiple purchase requests

    Hi, I am planning MRP run based on MRP area involving 2 storage locations I have 2 demand requirement coming from two sales orders having one line each. In MD04 I see I have shortage, so I run MRP Situation is SO1 - Qty - 10 PCE - storage location1 S