Dynamic object creation in java

Discussion in 'Java' started by rekha, Nov 11, 2008.

  1. rekha

    rekha

    Joined:
    Nov 11, 2008
    Messages:
    3
    Hi All,
    i have got class name dynamically in a string type, now need to create object of that class and call a method. please help:-(

    i tried following code but its not working

    String myclassName = textAgeList.item(0).getNodeValue().trim();
    // Object myObject = Class.forName(myclassName).newInstance();

    Class c= Class.forName(myclassName);
    Object m=c.newInstance();
    rekha, Nov 11, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry F. Harrison

    Dynamic creation of object problem

    Harry F. Harrison, Aug 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    465
    Scott Allen
    Aug 11, 2004
  2. 4Space
    Replies:
    16
    Views:
    649
    4Space
    Sep 15, 2003
  3. Andre Meyer
    Replies:
    9
    Views:
    292
    Jacek Generowicz
    Apr 8, 2004
  4. Andre Meyer
    Replies:
    1
    Views:
    578
    Peter Abel
    Apr 7, 2004
  5. jon wayne
    Replies:
    9
    Views:
    697
    Jim Langston
    Sep 22, 2005
Loading...

Share This Page