How to make a class object  from a string representation of the same

i have the name of a class whose object i want to make in the form of a string i.e. String s="S1"; i get this name after some prosessing. so what i want to do is to create an object of S1 which is actually one class that i have implemented.plz hlp. it is urgent.thnx in advance.

reflection api...
see java.lang.Class. Read the api docs.
mostly, u need to do the following:
Class myClass = Class.forName(s1);
Object x = myClass.newInstance();
reg
s giri

Similar Messages

  • How do I control my mac from another mac not in the same network?

    How do I control my mac from another mac not in the same network? Thanks

    You can do it manually, but it is much simpler if you use a tool such as Back To My Mac, LogMeIn, or something like that. Those programs enable you to connect to your computer through your router without you having to adjust the router settings manually.

  • How to make a Graphics2D object from a Graphics object?

    Hallo !
    Graphics g = pj.getGraphics();
    Graphics2D g2 = (Graphics2D) g;I get an Exception as follows:
    java.lang.ClassCastException: sun.awt.windows.WPrintGraphicsWrapper
    Is there an other possibility to to make a Graphics2D Object ? Or can I repair the error on an other way?
    Thank you Wolfgang

    Yes JBuilder makes a reference to this line.
    pj is a PrintJob.
    The only lines in this method for test are
    PrintJob pj = Toolkit.getDefaultToolkit().getPrintJob(p,"PrintWindow",null);
    Graphics g = pj.getGraphics();
    Graphics2D g2 = (Graphics2D) g;
    pj.end();Exception occurred during event dispatching:
    java.lang.ClassCastException: sun.awt.windows.WPrintGraphicsWrapper
    Wolfgang

  • How to create a Document object from a string.

    If I use the following code, the input String cannot contain "\n", otherwise, it generates errors.
    in the following code, inputXMLString is a String object that has xml content.
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(inputXMLString)));          How can I create a Document object from a string with "\n" in the string?
    Thanks.

    If I use the following code, the input String cannot
    contain "\n", otherwise, it generates errors.That's going to be a huge surprise to thousands of people who process XML containing newline characters every day without errors.
    Perhaps your newline characters are in the middle of element names, or something else that causes your XML to be not well-formed. I'm just guessing here, though, because you didn't say what errors you were getting.

  • How do I prevent a user from opening multiple instances on the same computer?

    On the site oldnavyweekly.com there is a .swf that prevents users from opening multiple instances of the site at the same time on the same computer. If you open the site, and try to open it a second time in another window, it won't load. You can't open the site again until the first window is closed. How did they implement this?
    From my analysis it is NOT:
    1. Cookies - The block still takes place if you try opening it in IE and also try opening it in Firefox simultaneously.
    2. Flash Cookies - The block still takes place if I disable flash cookies.
    3. IP Based Block - You are not blocked if you open the site on two separate computers with the same outbound IP address. From my analysis, their server does not assist in the block at all.
    It seems as if their .swf is creating some kind of global system-wide object that can be detected in other instances of the application on the same machine. How did they implement this?
    Thanks!

    you're welcome.
    actually, unless you take an extra step, the first opened swf will close.  if you want the 2nd to close, the initial receiving lc will send a message to sender that causes the sender to close.

  • How do you stop your phone from creating two albums with the same photos after syncing?

    When I first bought my phone I was able to sync my photos by checking the folder I wanted synced under iTunes. This put all those photos on photo library on my phone. I recently added more photos to that folder and tried to sync them it now put them in the photo library album and also created another album with my folder name. So I have two albums with the same photos. I tried in checking that folder in iTunes and of course they're not in my photo library. Please help. I don't want two albums with the same pics

    This is how Apple has always handled photos.  nothing has changed at all.
    Just as your music is in your library and you can access those exact same songs from a playlist, all of your synced pics are in the Photo Library and those exact same photos (NOT duplicates) can be accessed from the album name that you chose to sync.

  • How do I enable opening firefox from two different computers sharing the same home directory without having to delete a lock file (linux).

    I just don't want to have to delete a lock file - which has a purpose - in order to use firefox simultaneously from two locations on the network - where the home directory, i.e. .mozilla directory - is located

    You need to use two separate profiles if you want to have two Firefox instances open at the same time.
    See also http://www.mozilla.org/unix/remote.html

  • NewBie Q : How to make one clickable shape jump to a slide with the same name of the shape (button c_1 to slide c_1 f.e.) .

    I made some clickable placeholders on a masterslide
    Then : a new slide based on that masterslide
    and want to use one script or shared  action that says "on success jump to another slide with te samen name as the button...)
    Sorry for this unusual semantic language.
    But already thanks for answering!
    Lucas
    PS I'm using a trial version to try out a branched interactive scenario. A choice of a user leads tot anothe slide with a video reaction followed by other choices,...)

    Sorry, but I'm not a native English speaker, and I have some problems with your question.
    The only interactive object that is possible on a master slide is a shape button. What do you mean by a 'clickable placeholder'?  Why I like Shape Buttons - Captivate 6! - Captivate blog  explains possibilities with shape buttons.  Maybe the idea to have such a shape button on a master slide is not the best, because you cannot control objects on master slides since they do not have an ID. You cannot give a name to a shape button on the master slide, which means the scenario you are talking about is just impossible?
    Moreover: Captivate doesn't like to have the same name/label to be used for different objects. There are some exceptions, you can have an advanced action with the same name as the interactive object that is triggering that action, provided you label first the interactive object before labeling the action. With  "script" you probably mean an advanced action?
    If you tried to explain what you want to do as detailed as possible, maybe I could propose something. You'll see that my blog is focussed on advanced and shared actions. One other puzzling sentence is 'same name as the button'? Are you really talking about the name of the button or about the label ON the button?

  • How to make a group in contacts to send them all the same text?

    I am wondering if there is a way to make a group in contacts so I can send a text and have it go to all of the people in that group at once.  Help please.

    I don't think so. Search for an app in App Store or create a message with all contacts you want and use this to send message to this group of people.

  • Can I make a RandomAccessFile object from file in jar?

    There is some files in jar.
    I googled some articles that include how to make a input stream of a file in jar.
    I wonder if I can make a RandomAcessFile object from that file?
    ~may the force be with you~

    Shiny is all about highlights and contrast, and maybe reflections.  Sometimes a curve with a 'W' shape can do the job, but probably better to add highlights by painting with white on a new layer, blurring and reducing contrast.   If you upload your picture, it will be much easier to advise on the best route.

  • Setting the name of a new object from a string

    Is there anyway I can set the object name of a newly created
    object from a string?
    eg.
    (the code below generates a compile time error on the
    variable declaration)
    public function addText(newTxt:String, txt:String,
    format:TextFormat):void {
    var
    this[newTxt]:TextField = new TextField();
    this[newTxt].autoSize = TextFieldAutoSize.LEFT;
    this[newTxt].background = true;
    this[newTxt].border = true;
    this[newTxt].defaultTextFormat = format;
    this[newTxt].text = txt;
    addChild(this[newTxt]);
    called using>
    addText("mytxt", "test text", format);
    I could then reference the object later on without using
    array notation using mytxt.border = false; for example
    There are many a time when I want to set the name of a new
    object from a string.
    In this example I have a function that adds a new text object
    to a sprite.
    The problem is, if I call the function more than once then
    two textfield objects will exist, both with the same name. (either
    that or the old one will be overwritten).
    I need a way of setting the name of the textfield object from
    a string.
    using
    var this[newTxt]:TextField = new TextField()
    does not work, If I take the "var" keyword away it thinks it
    a property of the class not an object.
    resulting in >
    ReferenceError: Error #1056: Cannot create property newTxt on
    Box.
    There must be a way somehow to declare a variable that has
    the name that it will take represented in a string.
    Any help would be most welcome
    Thanks

    Using:
    var this[newTxt]:TextField = new TextField()
    is the right approach.
    You can either incrment an instance variable so that the name
    is unique:
    newTxt = "MyName" + _globalCounter;
    var this[newTxt]:TextField = new TextField();
    globalCounter ++;
    Or store the references in an array:
    _globalArray.push(new TextField());
    Tracy

  • How do I make a Datagram Packet from a String?

    I am looking to make a Datagram Packet from a string. If I send a command to a server that allows remote connections via UDP, such as "restart" it will restart the server. I can accomplish this easily through the fput() method of PHP.
    I want a Java version of my utility, and am using the DatagramSocket and DatagramPacket classes. I see that I need to make a byte array and put it inside a DatagramPacket. How would I go about putting the string "restart" into a byte array?
    Thanks,

    Use the following code to send a Datagram:-
    import java.io.*;
    import java.net.*;
    // This class sends the specified text as a datagram to port 6010 of the
    // specified host.
    public class UDPSend {
        static final int port = 6010;
        public static void main(String args[]) throws Exception {
            if (args.length != 2) {
                System.out.println("Usage: java UDPSend <hostname> <message>");
                System.exit(0);
            // Get the internet address of the specified host
            InetAddress address = InetAddress.getByName(args[0]);
            // Convert the message to an array of bytes
            int msglen = args[1].length();
            byte[] message = new byte[msglen];
            args[1].getBytes(0, msglen, message, 0);
            // Initilize the packet with data and address
            DatagramPacket packet = new DatagramPacket(message, msglen,
                                   address, port);
            // Create a socket, and send the packet through it.
            DatagramSocket socket = new DatagramSocket();
            socket.send(packet);
    }This uses argments, if you want a string change the code accordingly.

  • How do I create an object from a filename?

    I'm traversing directories and storing a list of files in a File array. Then I traverse the array looking at the extension of the file. If it is .java then I would like to instantiate it as a class so that I may pass the new object to another function which will examine its methods. I've tried Class.forName(file.getCanonicalPath()) and it throws a ClassNotFound exception. How can I create an object from a valid filename, please?

    Rick_Avlonitis wrote:
    If it is .java then I would like to </snip>.java files contain source code, they can't be "instantiated". Class.forName() takes a classname as parameter, i.e. "mypackage.MyClass". A class name is not a file name, and it doesn't have an extension. As stated in the other reply, you'll need to have the class on your class path.

  • How can i use class reference from an array effeciently?

    Hi,
    I made some test here with getting a class reference from an array and using the reference's methods or variables.
    Basically arrayEx is a container of type Array and it contains the Person's class instance in it. Num is a number extracted from the Person's instance
    Example #1----Strongly typed
    Var reference:Person;
    Var num:int;
    //Assignation
    reference=arrayEx[0];-----IT IS SLOW HERE
    //Use
    num=reference.number --- IT IS FAST HERE
    Example #2---Not typed
    Var reference:*;
    Var num:int;
    //Assignation
    reference=arrayEx[0]; ---- IT IS FAST HERE
    //Use
    num=reference.number ---IT IS SLOW HERE
    No matter what i change in both code like casting Person on arrayEx, i cant seem to make them work both fast at the same time
    If someone knows how, please tell me,
    Dominik

    Hi,
    I made some test here with getting a class reference from an array and using the reference's methods or variables.
    Basically arrayEx is a container of type Array and it contains the Person's class instance in it. Num is a number extracted from the Person's instance
    Example #1----Strongly typed
    Var reference:Person;
    Var num:int;
    //Assignation
    reference=arrayEx[0];-----IT IS SLOW HERE
    //Use
    num=reference.number --- IT IS FAST HERE
    Example #2---Not typed
    Var reference:*;
    Var num:int;
    //Assignation
    reference=arrayEx[0]; ---- IT IS FAST HERE
    //Use
    num=reference.number ---IT IS SLOW HERE
    No matter what i change in both code like casting Person on arrayEx, i cant seem to make them work both fast at the same time
    If someone knows how, please tell me,
    Dominik

  • How do you remove an object from a picture.  Newbie to program CS6

    how do you remove an object from a picture.  Newbie to program CS6

    Well, generally you can use the clone-stamp tool for one, shortcut is S. It basically allows you to take data from any part of the image and copy that over. What I do is draw on a new layer above the one to modify- make sure you select Sample:"This layer and below" in the top toolbar when doing so. Other ways include blending something on top of the object too, using different blending modes. Painting over it works too at times (rarely). It'd be easier if we knew a specific case though...

Maybe you are looking for