How to instantiate classes at run time with constructors having arguments?

I have to instantiate some classes in the run-time because they are plugins. The name of the plugin (pluginClassName) comes from a configuration file.
Currently I am doing this to achieve it:-
UIPlugin plugin = (UIPlugin)Class.forName(pluginClassName).newInstance();However, there is a disadvantage. I can not pass arguments to the constructor of the plugin.
public class RainyTheme extends UIPlugin {
  public RainyTheme() {
   // bla bla
  public RainyTheme(int x, int y , int width, int height) {
   // set co-ordinates
   // bla bla
  // bla bla bla bla
}Now if I want to instantiate this plugin at runtime and at the same time I want to pass the 4 arguments as shown in the second constructor, how can I achieve this?

I have no experience with JME and the limitations of its API, but looking at the API docs ( http://java.sun.com/javame/reference/apis.jsp ) it seems that there are two main versions, CLDC and CDC, of which CLDC is more limited in its API.
The Class class does not contain the methods getConstructor(Object[]) or getConstructors() in this version ( http://java.sun.com/javame/reference/apis/jsr139/java/lang/Class.html ), so it seems that if you are using CLDC then there is no way to reflectively call a constructor with parameters. You'd have to find another way to do what you want, such as use the noarg constructor then initialise the instance after construction.

Similar Messages

  • How to Load Classes in run time - Urgent

    Hi All,
    How to Load a class file from a .jar file in JDK1.1 with out using URLClassLoader. I have tried to extract the .jar file by file input stream and zipEntry classes and defineClass using the bytes i got from the stream , but the class loader fails to take the classes that are already loaded in the system.
    The customClassLoader that i created was not able to assign an object to the another reference variable that already in the JVM.Please i want to know how to assign or communicate between the objects of CustomclassLoader and SystemClassLoader?
    Please help me in this regard.
    Thanks in advance,

    Hi,
    The above code works in the straight way if the class is available in the classpath.
    I need to load a class by using custom class loader that i extends from classloader base class .
    I have to read a class file from a .jar file (in server) and load it in run time.Here i am able to read the bytes from the .jar file of the specified class file, but the class that i read extends some other class that is already loaded when i tried to create newInstance of the class i get Exceptions. Here the custom classLoader cannot find the loaded existing class in the JVM.can i get a solution for this situation

  • How to fill Lookup table run time with desired values in project server 2010.

    HI,
    is this possible to fill LookUp Table with some Desired Values at Runtime ??
    Or How to bind a LookUp table with DataBase  Table??

    Dear Rohan,
    You need to do this via PSI script for lookup table.
    Follow this blog Chris Boyd:
    http://blogs.msdn.com/b/project_programmability/archive/2006/11/08/adding-a-project-to-a-category.aspx
    Regards,
    Avinash kumar | Blog:http://avigr8.wordpress.com | If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.

  • How to invoke a class at run-time for primitive data types?

    Hi,
    I am trying to invoke classes at run-time.
    I am using Class.forName("className") for that where the "className" is also obtained at run-time .
    The problem I am getting is when the "className" is "int" or "char" etc. the call to Class.forName("int") etc. fails giving ClassNotFound error. It works fine for "className" is "java.lang.String" or "java.lang.Integer" etc.
    How can I correct this?
    thanks in advance-
    kg

    Hi,
    Thanks all for the valuable inputs.
    I have created a hashtable of primitive data types in the form of "int" as key and "Integer.TYPE" as the object in that element of the hashtable.
    Now there is another problem I am facing and that is of 'Casting at run-time'.
    Problem is there when the Database type is 'NUMBER' which returns me a "java.lang.BigDecimal" when I do a ResultSet.getObject("XXX") for that whereas the method in the javabean expects an "int" type.
    This causes "java.lang.IllegalArgumentException: argument type mismatch"
    So I want to cast it at runtime. How can I do it?
    Here is the code I am trying (which generates the above exception)
    public static void setBeanField(Class pCls,Object pObj,String pMethodName ,Object pColumnValue,Class
    pColumnTypeClass){
    try{
    if(pColumnValue!=null){
    Class[] paramTypes = new Class[]{pColumnTypeClass};
    Object[] args = new Object[]{pColumnValue};
    Method meth = pCls.getMethod(pMethodName,paramTypes);
    meth.invoke(pObj,args);
    }catch(Exception e){
    System.out.println("Exception in TestInrospection.setBeanField " + e);
    thanks in advance-
    kg

  • How can I test the running time of a method?

    c.What is the running time of your method smallest, as a function of n, the number of elements in the list? Use big-Oh notation.
    I quoated from a java problem..
    Anyone can tell me how I can test the running time? Thanks ! :D

    it depends on what is in the method. For example a for loop executed n times would have a O(n). A double for loop (each loopp run n times) will have O(n^2). Do this: determine how many times each loop in the method is run. This is the first term in your runtime equation. Do this for all other loops in the method and add them all together. Most other statements that are not iterative should have a constant runtime so O(1). For conditional statements, the runtime depends on the most time consuming portion of the statement. Once all these are added together, take the O(equation) which should just leave the biggest term. i.e. O(5n^2+3n+8) = O(n^2). Hope this helps.
    note: this does not apply to recursive methods

  • I sold my ipad 2 and didn't take out my apple id. how can i log off the ipad with out having it in hand?

    I sold my ipad 2 and didn't take out my apple id. how can i log off the ipad with out having it in hand?

    You can't. But the buyer more than likely restored it because he/she could not use your Apple ID.

  • How do I reset my security questions with out having to select a new apple id or a new password?

    How do I reset my secrit questions with out having to select a new apple id or a new password when I'm at the itunes store.

    You will be able to reset them via:
    appleid.apple.com
    If you do not know your password contact Apple's expresslane:
    expresslane.apple.com

  • My Iphone 5s message is showing it has a message but it doesnt. ive cleared out all messages, ive turned it off then on again how do I get rid of it with out having to reset my phone?

    My Iphone 5s message is showing it has a message but it doesnt. ive cleared out all messages, ive turned it off then on again how do I get rid of it with out having to reset my phone?

    just do a reset, you lose no data.
    hold down the home/sleep button together until you see the apple logo and then release.

  • LoadClass    (error loading a class which extends other class  at run-time)

    Hey!
    I'm using the Reflection API
    I load a class called 'SubClass' which exists in a directory called 'subdir' at run-time from my program
    CustomClassLoader loader = new CustomClassLoader();
    Class classRef = loader.loadClass("SubClass");
    class CustomClassLoader extends ClassLoader. I have defined 'findClass(String className)' method in CustomClassLoader.
    This is what 'findClass(String className)' returns:
    defineClass (className,byteArray,0,byteArray.length);
    'byteArray' is of type byte[] and has the contents of subdir/SubClass.
    the problem:
    The program runs fine if SubClass does not extend any class.
    If however, SubClass extends another class, the program throws a NoClassDefFoundError. How is it conceptually different?
    Help appreciated in Advance..
    Thanks!

    Because i'm a newbie to the Reflection thing, i'm notI don't see reflection anywhere. All I see is class loading.
    sure what role does the superclass play when i'm
    trying to load the derived class and how to get away
    with the errorWell... hint: all the superclass's stuff is not copied into the subclass.
    I am quite sure it fails to load the superclass because of classpath issues.

  • Print methods of a class at run-time

    Suppose I have a class. At run-time I get an object of that class. I want to print methods defined in that object using System.out.println(). How can I do that?
    Thanks

    Take a look at Object.getClass(). It returns a Class object. Then look at the methods within the Class class that you can invoke. Some of them return arrays of Method objects, for instance.
    Learn to read the API and experiment with the available methods you already have (such as getClass(), available for every object).
    http://java.sun.com/j2se/1.4.2/docs/api/index.html

  • How to design report at run time SSRS

    most of the time we point store procedure or table and then SSRS report designer show us field and we just drag drop those field on to report designer surface. after all we call those report programmatically and pass parameter and report shown on report
    viewer.
    now my company want that customer will customize the report who will see the report. they want to display all the fields in a form and just customer will select each field and place on report designer surface and give some input like filter condition like
    date range or employee id etc and report will be shown. also at run time if customer want they can add text or move existing field etc.
    i do not have any idea how could i do this with SSRS. if this is possible with SSRS then please guide me in such a way as a result i can start the job or if possible give me few relevant url of that kind from where i can get the idea. thanks

    You can also use report builder application to get most of these functionality. For that you'll just create and deploy a report model with required attributes from involved entities.
    Then use can consume the model within report builder and add required fields to report,filter etc
    see below videos for more details
    http://technet.microsoft.com/en-us/sqlserver/dd430326.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to open directory in run time using java

    Hi All
    i hava problem for open a directory in run time in java.please help me with code.

    Please elaborate what you mean by opening a directory. You can at all times access directory content via the File class.
    File myDir=new File(<pathToDir>);
    File[] directoryContent=myDir.listFiles();

  • How can I uninstall Labview run time engine from the machine?

    I understand that Labview has not given any provision to show customized 'License Agreement screen'. Isn't it? This is the main cause of my problem. Since I want to show our own license agreement (LA) screen, I made the one using Labview. To show this license agreement screen, I first install a small application which has only this LA screen with Labview run time engine. The customer can see License Agreement Screen with Labview Run Time Engine on his machine. If My customer accepts the LA, I will install the main application further by calling another setup.EXE file.
    If my customer selects 'Do Not Agree' to the LA, I will quit the installation process. Here I also want to 'uninstall' Labview Run Time Engine
    from his machine since he doesn't accept License. I would like to know how to uninstall Labview run time engine from his machine?
    Another way which I could think is to run the LA screen from the CD with Labview run time engine on the CD. I will start installing the main S/W to the customer's machine with LABview Run Time Engine only after he accepts License agreement. I would like to know how to run the Labview application from CD without installing run time engine on the target machine?
    Can anyone suggest solution to my problem?
    Thanks,
    Chander

    J-Tek,
    I would suggest re-installing the Run-time Engine and then uninstalling it after a reboot. Also, you can download a program called Msicuu.exe (for NT, 2000, XP or Msicu.exe for 9x) to help clean up the registry for uninstalled programs.
    Randy Hoskin
    Applications Engineer
    National Instruments
    http://www.ni.com/ask

  • How to install database in run time

    hi all
    i want to ask if i can install database as run time only and in this case how i can logon the sql ?,i want to install it as run tim such as developer 6 run tim
    is this possible?
    thanx

    first thank you for helping me
    and i will try to explain what i want to do in more details
    i'm using oracle database9i with developer 6i and i want to deliver an application was mad by this tools i know that i should setup the database and forms runtim only in at the customer computer the application -at the first- will work at only on one computer ,this computer will run as the client\server
    my question is
    if i can setup the database as run time only or i must setup complete at the customer computer?
    i tried to do that by choosing this option when installing database
    1-Oracle9i Client 9.2.0.1.0
    2-Run tim
    but after making this i can't connect with database
    i hope that if i can explain what i want to do

  • How to get VBELN in run time

    I have developped a custom driver program and a smartfor layout for sales order confirmation. And configured the program and layout against a output type.
    I go to VA02>Type an order number>
    Choose 'Issue output to' from Sales document menu. Then I will select the output type and press print preview button.
    In this case my custom driver program is called. My question is during this run time how do I get the VBELN for the current document that I have entered? Based on this VBELN, I am going to fetch the required data.
    Regds
    Rajesh

    I believe it should be coming in thru NAST as the object key?  In our custom print programs for sales documents, there is entry routine in the program which is defined in config.  The subroutine is called and NAST is avaiable during runtime,  the OBJKY is the field with the sales document number in it.
    tables:
            nast,                          "Messages
            *nast.                         "Messages
    form entry using return_code us_screen.
      clear retcode.
      xscreen = us_screen.
    * Retrieve misc data.
      select single vbpa~vbeln vbpa~kunnr adrc~name1 adrc~street adrc~city1
                    adrc~region adrc~post_code1 adrc~tel_number
                    adrc~fax_number
                       into corresponding fields of formdata
                          from vbpa
                            inner join adrc
                               on  vbpa~adrnr = adrc~addrnumber
                                  where vbpa~vbeln = <b>nast-objky</b>                                and vbpa~parvw = 'AG'
                                    and adrc~date_to = '99991231'.
    endform.
    Regards,
    Rich Heilman

Maybe you are looking for

  • IPhoto 11 won't let me buy book due to unplaced photos, but they are there!

    I have created many photo books in both iPhoto and Aperture and this has not happened before.  I click on the Buy Book button and it says I have unplaced photos and takes me to a page that clearly has all the photos placed. Any suggestions?  Thanks!

  • Oracle Tables Partitioning

    I am planning for table partitioning of existing tables... database is production 10gR1 i need it to upgrade to 11gR2 and also implement table partitioning. what should be the best way to do so with minimum downtime and zero data loss. Please advice.

  • Unable to see the buttons in the providers

    hi I have created new Providers in Portal .The places where edit, help etc buttons should be seen I am getting null written at that place. Please provide some help thanks in advance dhawanmayur

  • Autostart

    Hi First of all, excuse my poor english How can I stop Itunes to recognize automatically Audio CDs? I don´t want itunes to start auto. Greetings

  • IPad 2 screen went black all of a sudden while i was using it. what do i do

    i recently bought an iPad 2 its been working fine since. but today i was using it  and i was putting an app in a folder then all of a sudden the screen went black, iv tried pressing the home button and on/off  but nothing works