The use of reflectors to dynamically call objects

Hello

I have a class that has two methods and each method takes two parameters (method 1 takes entire / 2nd takes Double) and returns and integer. I would like to call these methods using Java.Reflectors, so I could do the instantiations of the dynamics and the method call.

I generated a class as shown experimental test harness below...

*========================================================*
public static void main(String[] args) {
        try {
            // Getting a Class available in the Pachage to Class Instance
            Class cls = Class.forName("testreflection.ClassMethods");
            
            // Instance of Current Class
            Main o_Obj = new Main();
            
            // Get the declared methods in the Class instand "cls"
            Method[] m_Methods = cls.getDeclaredMethods();
                        
            for(int i=0; i<m_Methods.length; i++){

                // Obtain the parameter types of each method
                Type[] typ_MethodParameterTypes = m_Methods.getGenericParameterTypes();

// Int array for Random Integer inputs as Parameters
int[] i_Prameter = new int[typ_MethodParameterTypes.length];
Random r_RandomInt = new Random();

for(int j=0; j<typ_MethodParameterTypes.length;j++){
// Just Display the Input Type
System.out.println(typ_MethodParameterTypes[j].toString());

i_Prameter[j]=r_RandomInt.nextInt();
//Display the Input value to the above type
System.out.println(i_Prameter[j]);
}
// Trying to invke the 1st Method in the Mehtod array
m_Methods[0].invoke(o_Obj, i_Prameter);
}
} catch (IllegalArgumentException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
//} catch (InstantiationException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

}
*==============================================================*


 THen I am getting the following error.... Can any one help me...


int
-1680302169
int
-1149051431
Mar 30, 2011 11:02:53 AM testreflection.Main main
SEVERE: null
java.lang.IllegalArgumentException: object is not an instance of declaring class
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at testreflection.Main.main(Main.java:52)

Edited by: EJP on 30/03/2011 12:17: added the code tags. Please use them.

Edited by: JLearner on Mar 29, 2011 6:18 PM

Edited by: JLearner on Mar 29, 2011 6:20 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

m_Methods [0] .invoke (obj, i_Prameter);

m_Methods [0] .invoke (obj (Object []) i_Prameter);

Complicated to explain why a beginner.

As Kayaman, I'm curious to know the assumptions and no error check here.

Tags: Java

Similar Questions

  • is it possible to apply the sort on the columns added to a dynamic display object?

    Hi all


    We use JDeveloper Studio Edition Version 12.1.3.0.0 and deployed on GlassFish Server Open Source Edition 3.1.2.2 (build 5) and connect to the SQLServer database.


    We have created a dynamic display object in the AM Impl, all objects in view columns are added dynamically.


    All lines are displayed correctly, but when sorting columns data disappear. (point of view are being refreshed, of course).


    is it possible to apply the sort on the columns added to a dynamic display object?

    This is how we show data in the JSF page:


    < af:table lines = ' #{bindings. " DynamicVO.rangeSize}' fetchSize = "#{bindings." DynamicVO.rangeSize}.

    emptyText = "#{bindings." DynamicVO.viewable? "{'No data to display.': 'Access Denied.'}".

    var = 'row' rowBandingInterval = '0' value = ' #{bindings. " DynamicVO.collectionModel}.

    selectedRowKeys = ' #{bindings. " DynamicVO.collectionModel.selectedRow}.

    selectionListener = "#{bindings." DynamicVO.collectionModel.makeCurrent}.

    rowSelection = "single" id = "t1" >

    < af:forEach elements = "#{bindings." Var DynamicVOIterator.attributeDefs}' = 'def' varStatus = 'vs' >

    "< af:column headerText =" #{def.propertyMap.label} "sortable ="true"sortProperty =" #{def.name} ".

    ID = "clmn$ {vs.index}" >

    < af:outputText value = "#{row [def.name]}" id = "ot1" / > "

    < / af:column >

    < / af:forEach >

    < / af:table >




    Thanks guys, I created a custom class that contains a model that can be sorted in a pod of support and I have to the adf work table it and it is very good about sorting.

    JSF:

    Rows = "#{pageFlowScope.crudBean.dynamicTable.collectionModel.RowCount} '"

    contentDelivery = 'immediate' var = 'row' rendered = 'true '.

    Binding = "#{backingBeanScope.crudBackingBean.tasksTable} '"

    selectionListener = "#{backingBeanScope.crudBackingBean.customListener} '"

    "rowSelection ="single"id ="t1"partialTriggers =": pt_gr2 "columnStretching =" column: clmn0 ">

    inlineStyle = "width: 100px;"  ID = "clmn$ {vs.index}" > "

  • can we use service legend to dynamically call business service in OSB

    My requirement is: contact service issue. moments of for - each loop in OSB. Node road that we cannot use in the foreach loop.

    can we use service legend to call business several times? and how can we pass endpoint url to business service using the legend of service.

    Please help me.

    Yes you can use routing options to override the legend service endpoint url. See

    http://docs.Oracle.com/CD/E23943_01/admin.1111/e15867/proxy_actions.htm#i1315299

    The action of routing Options can be used when the context variable $outbound is valid. It can be added to the following actions:

    • Publish
    • Dynamic publishing
    • Publish the Table
    • Legend of service
    • Routing
    • Dynamic routing
    • Routing table
  • Choose the platform correct blackberry 10 for the use of functions such as call history, use of data, message records

    I want to design a blackberry 10 application that can fetch all call logs, data internate, messages through the application usage. Please help me choose the right platform that can provide all the APIs that are required for this application. 10 webworks Blackberry and Android runtime dosen't supports all API.

    Thank you.

    You can watch here

    https://developer.BlackBerry.com/native/documentation/Cascades/device_platform/invocation/invoking_c...

  • dynamically called vi, PDM invalid file reference

    Hello

    I can't explain a strange behavior, I hope someone can give me a hint.

    First of all, do not ask why I need this way to go, I would like to understand why this is happening.

    We have a FGV which has 3 actions: Init, write data and close. It works on the TDMS files. The action of the init creates a TDMS file reference that is stored in a shift register to be prepared, used by writing and finally narrow cases.

    Everything is OK, if I use this FGV simply in a main VI directly from the block diagram. So that I can init, write data and finally close the PDM file.

    However, for some reason, appeared a new requirement: to be able to 'Init' and 'Close' the TDMS file using the FGV, but within a dynamically called VI (a pop-up window that may not stop the execution of the appellant).

    So in primary VI, I call dynamically VI one another by using the asynchronous call (flag x 80, "call and forget" method), and it dynamically called VI fires the FGV TDMS.

    When I probe the reference of TDMS files, I can see that it gets its value correctly after the case 'Init' of fire. After this 'init' which happened (from Dynamics called VI), a location in the MAIN VI starts calling this FGV with enum action 'Write '. I can see via sensors, the case of writing Gets the same number of REF TDMS file which has been stored in the shift register after the case 'Init '.

    But even so, the VERY first function TDMS write throws an error msg "TDMS file invalid reference '! How is it possible, if the file reference is OK and the same as that created by the function 'File open TDMS' in case 'init '?

    Again, if I execute 'init' action also directly the main VI, not a third dynamically called VI, everything is OK, it works.

    I hope that my explanation is not too bad

    Thanks for the tips and if no idea, I'll try to recreate/replicate this behavior in a test project that is small, and I'll post it...

    The problem is that when the dynamic called vi stops all references that he open invalid.

    To see what I want to say, change the dynamics vi delay like 30 seconds before she stops, the savings loop works fine until the dynamics vi stops, then the error returns.

    Mike...

  • With the help of dynamically called screw in TestStand deployment

    I write code to interface with a & Rohde Schwarz ZNB Network Analyzer.  I use LabVIEW 8.2 and TestStand 3.5.  For reference the ZNB driver is available here: R & S of ZNB Driver.  I use a slightly older version of the driver, some before they needed to LabVIEW 2009.  I am writing all the code on a development machine that has the full version of TestStand/LabVIEW and it works on another machine that has the TestStand deployment license.

    This driver is dynamically linked to some things he needs.  I am able to operate with simple LabVIEW EXEs but not in TestStand deployments.  The following excerpt comes from their documentation, explaining a little about how the driver works and how to use in LabVIEW EXEs.

    3.4.2 How to generate executables or libraries in LabVIEW driver kernel drivers instrument based on attributes is dynamically bound to any VI performed during execution. This can be recognized by the LabVIEW application builder. The LabVIEW application builder follows all the static dependencies and include them in the package distributed at the generation of an executable file.

    To create an executable in LabVIEW, please manually add all the screws in the \PREFIX \_utility\callbacks folder to the LabVIEW project. In the case of project based please add private to your project folder. With this reference manual, the driver core is included in the compilation and the driver core is accessible during execution.

    I can't get this to work in TestStand deployments at all.  I can't even connect to the device since the VI Init has these issues.  I get the same error for all the various attempts that I made.  The same error is that when you add manually the screws for the LabVIEW EXE.

    Error-1073807346

    Property in Rohde & Schwarz Vector Analyzer.lvlib:rsidr_core_session_fgv.vi-> network node

    Rohde & Schwarz Vector Network Analyzer.lvlib:rsidr_core_check_error.vi->

    Rohde & Schwarz Vector Network Analyzer.lvlib:rsidr_core_attribute_write_int.vi->

    Rohde & Schwarz Vector Network Analyzer.lvlib:rsidr_core_attribute.vi:3->

    Rohde & Schwarz Vector Network Analyzer.lvlib:rsvna.vi:2->

    Example 1 setting of the Instrument 24Default .vi:1->

    Rohde & Schwarz Vector Network Analyzer.lvlib-> efault Instrument Setup.vi

    Rohde & Schwarz Vector Network Analyzer.lvlib:Reset.vi->

    Rohde & Schwarz Vector Network Analyzer.lvlib:Initialize.vi->

    Connection of ZNB testing.VI

    VISA: (Hex 0xBFFF000E) the given reference of session or the object is not valid.

    So far, I tried the following, all solutions producing this same error.  I struggled with this and turned off for awhile then maybe there are other solutions attempts I forget.

    (1) it looked like a lot of the report to go to the private folder were finished in SupportVIs.  I manually pasted the rest there, too.

    (2) I added all driver files on my workspace and included in the files with the rest of my deployed screws.

    (3) I added all driver files on my workspace and said pilot TestStand to deploy them to the original location in Program Files.

    Someone at - it ideas?  R & S didn't even know what was TestStand, so that they could not help me.

    I was finally able to solve this problem on mine, the other day.  I brought the Network Analyzer to my office and did a lot of tests in this way.  Eventually, I discovered that I needed to include the folder private pilot deployment, what I was doing in one of previous attempts.  It turns out that you must also maintain the original of this file directory structure when you include it, otherwise dynamic calls are not looking in the right place.  Once it worked on my PC, I got it on the machine test and worked as well.

  • Switch on the dynamic call

    I use packet sniffer example in my code with a few changes to calculate the delay of my data.

    I need to make a dynamic call to run this VI at some point my main code and stop at another point.

    Just to test I put some delays between market, stop and get the time as below:

    But in VI that I call, the stop button is inside a structure of event... like here:

    So... even if I try to stop the VI in my dynamic appeal, it seems that my VI will not read this change... only read if I manually stop the VI.

    so I try to stop at the first VI but does not stop... what could be a solution for this?

    Thank you

    Thai

    Problem solved. I just inserted the stop button in the same case where is Timeout, now I can guarantee you that this value will be read.

  • Re-use of dynamically called code of target in real-time on PC

    I have a code that is deployed on a target in real time what I call dynamically. I also want to use the same code dynamically on a PC in the same project.

    This works very well when you run interpreted code in form. However, I can't add the dynamic called VI to build on my PC specification if the VI is under the aim of RT in the project. I can only include it in the build specification that is in conjunction with the software to the target of the RT.

    How can I use this VI dynamically in the ad for the construction specifications and places without having two copies of it?

    I actually found a way using a static reference of vi:

    Rather than providing a path to the file of the 'open' vi reference, simply load the VI statically and I then enter its name to open an instance, re-entering. This approach has the advantage of process Dynamics called VI as if it was dropped on the block diagram - I don't have to explicitly include the vi file in the build specification.

  • The use of bind variables in dynamic query created for Ref Cursor

    Hello

    I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
    The application is currently using literals instead of bind variables.

    code snippet of the above is
    strSql: = "select * from emp where 1 = 1 and ().

    loop cursor1
    If cond is true then
    strSql = strSql | "ename = ' |" Cursor1.ColumnName;
    end loop;

    Open cursor2 for strSql;

    How to use links in the example above.

    sb92075 wrote:

    user13019948 wrote:
    Hello

    Here is the code I have my trying to change literal-based link to the base.

    What do you mean by "based bind?

    who, what, how determines the values to be 'bound '?

    He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.

    If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.

    This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of

    AND t_names(i) = t_values(i)
    

    for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of

    select description from attribute where attribute_id = :b1 and name = :b2
    

    by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).

    declare
       k_sql_base        constant varchar2(500) := 'select description from attribute';
    
       t_names           constant varchar2_t := varchar2_t('attribute_id',  'name');
       t_values          constant varchar2_t := varchar2_t('1012',          'ISIN');
    
       l_sql             varchar2(500) := k_sql_base;
       l_rows_fetched    integer := 0;
       l_value           varchar2(4000);
    
       l_cursor_handle   integer;
    
    begin
       -- Construct the SQL statement with column names and bind variables e.g.
       -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2'
       for i in t_names.first .. t_names.last loop
          l_sql := l_sql ||
             case i
                when t_names.first then ' where ' else ' and '
             end ||
             t_names(i) || ' = :b' || i;
       end loop;
    
       dbms_output.put_line('SQL statment = ' || l_sql); 
    
       -- Parse the statement we built above (the remaining steps require a parsed cursor):
       l_cursor_handle := dbms_sql.open_cursor;
       dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native);
    
       -- Associate the 1st column of output with variable l_value - required for SELECT statements:
       -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string -
       -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different.
       -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.)
       dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000);
    
       -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE)
       for i in t_values.first .. t_values.last loop
          dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i));
          dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i));
       end loop;
    
       -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result):
       l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle);
    
       -- 'Returns value of the cursor element for a given position in a cursor'
       -- Copy the value of column 1 to variable l_value (has to match
       -- dbms_sql.column_value(l_cursor_handle, 1, l_value);
       dbms_sql.column_value(l_cursor_handle, 1, l_value);
    
       dbms_output.put_line('Result = ''' || l_value || '''');
    
       dbms_sql.close_cursor(l_cursor_handle);
    end;
    

    Hope that helps...

  • Using the label for datagrid created dynamically function

    I am creating a data grid dynamically based on the data returned by a script from the server call.

    I know that some of my data will be nested so I need to use a label function to check that these data are displayed in the datagrid control

    All of the examples of the use of a label function that I can find seem to have hard coded as in the following example columns

    < mx:columns >
    < mx:DataGridColumn headerText = "Name" dataField = "NomMenu" / >
    < mx:DataGridColumn headerText = "Vegetarian" labelFunction = "displayVegetarian" / >
    < mx:DataGridColumn headerText = "Peanuts" labelFunction = "displayPeanuts" / >
    < mx:DataGridColumn headerText = "Quantity" labelFunction = "displayQuantity" / >
    < mx:DataGridColumn headerText = 'Price' labelFunction = "displayPrice" / >
    < mx:DataGridColumn headerText = "Total industry" labelFunction = "displayLineTotal" / >
    < / mx:columns >

    However, I create my columns of the DataGrid dynamically if cannot use the < medium to achieve mx:DataGridColumn

    My code works as follows

    for (var i: uint = 0; i < xlColumns.length (); i ++) {}

    DGC = new DataGridColumn();
    dgc.dataField = "componentScores.ScoreValue" <-THIS NEEDS to USE A LABEL FUNCTION
    dgc.headerText = _qualificationSummaryScreenData.getComponentTitle (componentIndex);

    }

    I've highlighted above where I need to use a label function. I really hope that someone can help me here that I am currently taking one step forward and two steps backward with Flex right now and already several days behind on this project.

    Thank you very much

    Paul

    I do not exactly remember the syntax, but you can assign a function to the labalFunction property:
    dgc.labelFunction = myHandlerFunction; something like that

    Have you tried that yet?

    Tracy

  • using my yahoo Messenger to call the voice call, I can hear them but they don't hear me.

    update my windows Repir
    My problem in my computer when I use the control panel but I reallydont know my computer problem im using my yahoo Messenger to call calll voice to my family, I can hear them, but the problem I can not hear them

    Hi Kimberly,

    Please provide more details - such as what exactly is the problem with Windows Update?  Work any or you have problems with only a few updates (and if so, what are the numbers KB)?  Can update you manually from the Microsoft Download issue KB site (assuming that you can get to the point where you can even see that)?  Is the problem with all forms of update or automatic updates?  When did start?  Is the only problem that you encounter using the Panel of configuration-Windows Update?

    As far as Yahoo Messenger goes, I recommend you seek assistance for their support to the: http://help.yahoo.com/kb/index?locale=en_US&page=product&y=PROD_MSNG&pir=7V.5laVibUnuoUu5c5XhZBBabICc7x5O4gEqzWIp0oGQmrFMhkLSxkV35MZ8jMUxDeQJkHWotyOSbrdkRCYfcW.Bvc7wn9THHnEG5w- dig deeper, I found a chat to help option in addition help topics.

    I hope this helps.

    Good luck!

  • What is the use of RAS calling card?

    What is the use of RAS calling card? And how do I uninstall?

    Hello coco Amaravadi,

    Given that the problem is related to the RAS asynchronous card, it would be better suited on the TechNet support forum. I suggest you post your question on the following link.

    http://social.technet.Microsoft.com/forums/en/categories/

  • In Windows 3.1, I had the ability to send and receive calls by using a modem, it is possible to do it on Vista? If yes how?

    phone calls in vista?

    In Windows 3.1, I had the ability to send and receive calls by using a modem, it is possible to do it on Vista? If yes how?

    The game, February 16, 2012 21:46:49 + 0000, metalfare wrote:

    In Windows 3.1, I had the ability to send and receive calls by using a modem, it is possible to do it on Vista? If yes how?

    This isn't a problem of version of Windows. Must see with what software
    you are running. Yes, if you use a program that has this feature, you
    can do.
    Ken Blake, Microsoft MVP

  • How to get the contact details of the contact list to the use of the incoming call number?

    Hello

    I need callid, name, name of the company from the list of contacts to the use of the incoming number. If anyone has a solution please reply me as soon as possible.

    I have code below

    void ApplicationUI::onCallUpdatedd(const bb::system::phone::Call &call)
    {
        CallState::Type state = call.callState();
        //qDebug() << "call updated: callId=" << call.callId() << " callState="
        //  << state;
        if (state == bb::system::phone::CallState::Connecting
                || state == bb::system::phone::CallState::Connecting) {
            qDebug() << "call connecting";
        } else if (state == bb::system::phone::CallState::Connected) {
            qDebug() << "call connected";
        } else if (state == bb::system::phone::CallState::Failed) {
            qDebug() << "call Failed";
        } else if (state == bb::system::phone::CallState::Disconnected) {
            qDebug() << "call Disconnected";
        } else if (state == bb::system::phone::CallState::Incoming) {
            qDebug() << "call Incoming";
        } else {
            qDebug() << "Invalid";
        }
    }
    

    then, how I got the calling detail like number, name, company ect... call id?

  • The use of SQLite to store the JSON object

    Hello

    Can someone guide on how to store a JSON object returned after the use of the Adobe provide parser JSON which returns the native object

    as

    resultobject = JSON.decode (data)

    Where the data is a JSON string.

    The 'result' object is a complex subject, but I would like to keep this object because it is in the SQLite database.

    I tried BLOB for the column type but doesn't seem to work to store this object. Ideally, I prefer to use this way to avoid the redesign of the main code as I am currently using the SharedObject method.

    Any ideas?

    Can you just store the data as a BLOB string?

Maybe you are looking for