Possible to create an object from a String?

Hi,
is is somehow at all possible to create an object from a String ?
If we have etc.
String txt = "Carrot()";
Is it then possible to somehow cast that String and interpret it as a class type that it should make an object of ?
Like
new txt; - would then give me the same as new Carrot(); ?
Hope you understand what i mean.
Martin From... :-)

Class.forName("some.package.Carrot");

Similar Messages

  • Can you create an object from a string

    I have been working on creating a dynamic form, creating the
    form items from an xml file. I am getting very close to conquering
    this task. I will share it when it's complete.
    However, I am stuck at the moment trying to create an object
    from a string. For example, if the xml item is an HBox I want to
    create an HBox. Like this: parentObject = new arrayOfFormItems[
    index ]..type ()
    This isn't working. First, is this possible using some syntax
    I am unaware of in Flex? I don't want to use a large if or case
    statement if possible.
    Thanks in advance for your help!

    Thank you very much. Indeed that did solve the one problem. I
    missed the casting as a Display Object. That is awesome!
    I do still however, have to instantiate one of every item I
    want to dynamically create or I get the following error when I try
    to create a dynamic object that I have not instantiated before.
    ReferenceError: Error #1065: Variable HBox is not defined.
    at global/flash.utils::getDefinitionByName()
    at MyForm/buildForm()
    at DynamicForm/::onComplete()
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/flash.net:URLLoader::onComplete()
    I read that you have no choice but to instantiate one of each
    type to force the linker to link the code for that class into the
    .swf. Unless you know another way to force it.
    This is what I have in my Application mxml to get it to work:
    <mx:HBox>
    <mx:Text visible="false"/>
    <mx:TextArea visible="false"/>
    <mx:TextInput visible="false"/>
    <mx:DateField visible="false"/>
    </mx:HBox>
    And those are the types I'm using to test with. . . I will
    have to add all the others I want to use as well . . .

  • 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.

  • 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

  • Dynamically create Value Objects from XML file

    Hi
    I want to create a value object from Xml file dynamically,like in the xml file i have the name of the variable and the datatype of the variable.is it possible do that,if so how.

    Read about apache's Digester tool. This is part of the Jakartha project. This tool helps in creating java objects from the XML files. I am not sure, if that is what u r looking for.

  • Why can't I create new object from a class that is in my big class?

    I mean:
    class A
    B x = new B;
    class B
    and how can I solve it if I still want to create an object from B class.
    Thank you very much :)

    public class ItWorksNow  {
      public ItWorksNow() {
      public static void main ( String[] argv )  throws Exception {
        ItWorksNow.DaInnaClass id = new ItWorksNow().new DaInnaClass();
      public class DaInnaClass {
    }

  • Create Business Partner from XMl String not a file

    Hi,
    Is it possible to create a BP from an XML string. 
    I know about GetBusinessPartnerFromXml(string FileName, int index)
    but I dont want to save the string in a file before creating a BP from it
    Hope there's a method to do that

    Marc,
    This looks like it is a duplicate of this post, so I am closing this thread as it looks like you answered your own question!
    Create Business Partner from XMl String not a file
    Eddy

  • Create Class objects from an Array of File Objects

    Hi There,
    I'm having extreme difficulty in trying to convert an array of file objects to Class objects. My problem is as follows: I'm using Jfilechooser to select a directory and get an array of files of which are all .class files. I want to create Class objects from these .class files. Therefore, i can extract all the constructor, method and field information. I eventually want this class information to display in a JTree. Very similar to the explorer used in Netbeans. I've already created some code below, but it seems to be throwing a NoSuchMethodError exception. Can anyone please help??
    Thanks in advance,
    Vikash
    /* the following is the class im using */
    class FileClassLoader extends ClassLoader {
    private File file;
    public FileClassLoader (File ff) {
    this.file = ff;
    protected synchronized Class loadClass() throws ClassNotFoundException {
    Class c = null;
    try {
    // Get size of class file
    int size = (int)file.length();
    // Reserve space to read
    byte buff[] = new byte[size];
    // Get stream to read from
    FileInputStream fis = new FileInputStream(file);
    DataInputStream dis = new DataInputStream (fis);
    // Read in data
    dis.readFully (buff);
    // close stream
    dis.close();
    // get class name and remove ".class"
    String classname = null;
    String filename = file.getName();
    int i = filename.lastIndexOf('.');
    if(i>0 && i<filename.length()-1) {
    classname = filename.substring(0,i);
    // create class object from bytes
    c = defineClass (classname, buff, 0, buff.length);
    resolveClass (c);
    } catch (java.io.IOException e) {
    e.printStackTrace();
    return c;
    } // end of method loadClass
    } // end of class FileClassLoader
    /* The above class is used in the following button action in my gui */
    /* At the moment im trying to output the data to standard output */
    private void SelectPackage_but2ActionPerformed(java.awt.event.ActionEvent evt) {
    final JFileChooser f = new JFileChooser();
    f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int rVal = f.showOpenDialog(Remedy.this);
    // selects directory
    File dir = f.getSelectedFile();
    // gets a list of files within the directory
    File[] allfiles = dir.listFiles();
    // for loop to filter out all the .class files
    for (int k=0; k < allfiles.length; k++) {
    if (allfiles[k].getName().endsWith(".class")) {
    try {
    System.out.println("File name: " + allfiles[k].getName()); // used for debugging
    FileClassLoader loader = new FileClassLoader(allfiles[k]);
    Class cl = loader.loadClass();
    //Class cl = null;
    Class[] interfaces = cl.getInterfaces();
    java.lang.reflect.Method[] methods = cl.getDeclaredMethods();
    java.lang.reflect.Field[] fields = cl.getDeclaredFields();
    System.out.println("Class Name: " + cl.getName());
    //print out methods
    for (int m=0; m < methods.length; m++) {
    System.out.println("Method: " + methods[m].getName());
    // print out fields
    for (int fld=0; fld < fields.length; fld++) {
    System.out.println("Field: " + fields[fld].getName());
    } catch (Exception e) {
    e.printStackTrace();
    } // end of if loop
    } // end of for loop
    packageName2.setText(dir.getPath());
    }

    It's throwing the exeption on the line:
    FileClassLoader loader = new FileClassLoader(allfiles[k]);
    I'm sure its something to do with the extended class i've created. but i cant seem to figure it out..
    Thanks if you can figure it out

  • How to create and object from an arrayList

    Hi I want to create an object from an arrayList.
    here is my code...
    BillingQueryParam billingQueryParam = new BillingQueryParam();
    /*This BillingQueryParam and billingItemManagerActionForm has getter and setter method for following attributes.
    private int billingItemId;
    private String[] paramName;
    private String[] defaultParamValue;
    List billingQueryParamList = new ArrayList();               
    for(int i = 0; i < billingItemManagerActionForm.getParamName().length; i++) {
         billingQueryParam.setParamName(billingItemManagerActionForm.getParamName());
    for(int i = 0; i < billingItemManagerActionForm.getDefaultParamValue().length; i++) {
      billingQueryParam.setDefaultParamValue(billingItemManagerActionForm.getDefaultParamValue());
         billingQueryParam.setBillingItemId(billingItem.getBillingItemId());
         billingQueryParamList.add(billingQueryParam);
    System.out.println("****** ArrayList Size-->"+billingQueryParamList.size());
    for (Iterator iter = billingQueryParamList.iterator();iter.hasNext();) {
         billingQueryParam = (BillingQueryParam)iter.next();
          System.out.println("****** BillingItemId-->"+billingQueryParam.getBillingItemId());
          System.out.println("****** Param Name-->"+billingQueryParam.getParamName()); //printing an array of paramName
          System.out.println("****** Default param value-->"+billingQueryParam.getDefaultParamValue());
    }Here after iterating this list I want to create an object of billingQueryParam which contains a single value of itemId, paramName,paramTypeId and defaultParamName and I want to persist this object in database.
    Please help...!!!
    Thanks

    Now this is too much.. Do i need to tell this thing to u as well. How did u come to this forum?
    Can't u see link to Java programming forum at the top.

  • HT204053 the only way to creat an icloud account is with a ipad, iphone or imac. is it possible to creat the account from my windos PC? i already downladed i cloud, and i have an Apple ID but Not an Icloud account/

    the only way to creat an icloud account is with a ipad, iphone or imac. is it possible to creat the account from my windos PC? i already downladed i cloud, and i have an Apple ID but Not an Icloud account/

    Isa Garduño wrote:
    the only way to creat an icloud account is with a ipad, iphone or imac Apple computer.
    As you already knew, no, you cannot create a new iCloud account from anything but the above devices.
    http://support.apple.com/kb/HT4436

  • 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.

  • Is it possible to create foreign key from composite key in other table.

    SQL> desc PRODUCT_CONFIG_OPTION;
    Name Null? Type
    CONFIG_ITEM_ID NOT NULL VARCHAR2(20) --composite primary key
    CONFIG_OPTION_ID NOT NULL VARCHAR2(20) --composite primary key
    CONFIG_OPTION_NAME VARCHAR2(100)
    DESCRIPTION VARCHAR2(255)
    SEQUENCE_NUM NUMBER(18)
    LAST_UPDATED_STAMP TIMESTAMP(6)
    LAST_UPDATED_TX_STAMP TIMESTAMP(6)
    CREATED_STAMP TIMESTAMP(6)
    CREATED_TX_STAMP TIMESTAMP(6)
    SQL> DESC PRODUCT_CONFIG_ITEM;
    Name Null? Type
    CONFIG_ITEM_ID NOT NULL VARCHAR2(20)
    CONFIG_ITEM_TYPE_ID VARCHAR2(20)
    CONFIG_ITEM_NAME VARCHAR2(100)
    DESCRIPTION VARCHAR2(255)
    LONG_DESCRIPTION CLOB
    IMAGE_URL VARCHAR2(255)
    LAST_UPDATED_STAMP TIMESTAMP(6)
    LAST_UPDATED_TX_STAMP TIMESTAMP(6)
    CREATED_STAMP TIMESTAMP(6)
    CREATED_TX_STAMP TIMESTAMP(6)
    SQL> desc product;
    Name Null? Type
    PRODUCT_ID NOT NULL VARCHAR2(20)
    PRODUCT_TYPE_ID VARCHAR2(20)
    PRIMARY_PRODUCT_CATEGORY_ID VARCHAR2(20)
    MANUFACTURER_PARTY_ID VARCHAR2(20)
    FACILITY_ID VARCHAR2(20)
    INTRODUCTION_DATE TIMESTAMP(6)
    SUPPORT_DISCONTINUATION_DATE TIMESTAMP(6)
    SALES_DISCONTINUATION_DATE TIMESTAMP(6)
    SALES_DISC_WHEN_NOT_AVAIL CHAR(1)
    INTERNAL_NAME VARCHAR2(255)
    BRAND_NAME VARCHAR2(100)
    COMMENTS VARCHAR2(255)
    =========
    CREATE TABLE PROD_CONFIG_PROD_CONFIG_OPTION (
    PRODUCT_ID VARCHAR2(20),
    CONFIG_ITEM_ID VARCHAR2(20),
    CONFIG_OPTION_ID VARCHAR2(20),
    PAGE_NUM_TO NUMBER(18),
    ALTERNATE_PAGE_NUM_TO1 NUMBER(18),
    ALTERNATE_PAGE_NUM_TO2 NUMBER(18),
    ALTERNATE_PAGE_NUM_TO3 NUMBER(18),
    LAST_UPDATED_STAMP TIMESTAMP(6),
    LAST_UPDATED_TX_STAMP TIMESTAMP(6),
    CREATED_STAMP TIMESTAMP(6),
    CREATED_TX_STAMP TIMESTAMP(6),
    CONSTRAINT PK_PROD_CAT_CONFIG_MOD PRIMARY KEY (PRODUCT_ID),
    CONSTRAINT FK_PRODUCT_ID FOREIGN KEY (PRODUCT_ID) REFERENCES PRODUCT(PRODUCT_ID),
    CONSTRAINT FK_CONFIG_ITEM_ID FOREIGN KEY (CONFIG_ITEM_ID) REFERENCES PRODUCT_CONFIG_ITEM(CONFIG_ITEM_ID),
    CONSTRAINT FK_CONFIG_OPTION_ID FOREIGN KEY (CONFIG_OPTION_ID) REFERENCES PRODUCT_CONFIG_OPTION(CONFIG_OPTION_ID) )
    TABLESPACE DATA_SMALL
    i try to create this table if i omit 3rd foreign key constraint then table successfully created.but including trd foreign key constraint it return error "ORA-02270: no matching unique or primary key for this column-list"
    i checked everything is it possible to create foreign key from composite key in other table.

    And
    CONSTRAINT FK_CONFIG_OPTION_ID FOREIGN KEY (CONFIG_ITEM_ID,CONFIG_OPTION_ID) REFERENCES PRODUCT_CONFIG_OPTION(CONFIG_ITEM_ID,CONFIG_OPTION_ID)
    ?

  • How to create session id from different string controls

    how to create session id from different string controls

    fais,
    Please create the VI you are talking about and save some default data into all of the controls. Also on the front panel, place the session ID that should be generated by that data. Now, post your VI to a response so I can download it. I can then take this VI and help you create the functionality. (Please post what version of LabVIEW you are using.)
    My guess it that you are going to need to use a good number of string concatenations as well as a few string indexes to get parts of strings out. As for the date, you can use a Property node with the Numeric Text.Text property to get the actual string displayed on the front panel for the date and parse out the parts that you want.
    Randy Hoskin
    Applications Engineer
    National Instruments
    h
    ttp://www.ni.com/ask

  • Is it possible to clone an object from one image and paste it on another image?

    Is it possible to clone an object from one image and paste it on another image in Aperture?

    As Frank said,
    but Aperture has a nice clone tool - the drawback is, that it only works within one image.
    What I sometimes do - as a workaroud, when I want to use the clone brush, is to combine the image I want to clone from and the image I want to clone into, into one single image by printing them together to pdf as jpeg. Then I can clone from the second to the first, for example, to be able to add an fairy to a flower: Picking up the head of the fairy in the right image and brushing it into the left one. Occasionally I prefer the Aperture brush to the Photoshop lasso.

  • Is it possible to create an activity from the Agenda?

    Hi Experts,
    We noticed that it's possible to create a note from SSC1 Tcode but not an activity.
    When we create an activity (appointment), it appears in the agenda but  we can't manage to create it from the agenda.
    Is there any possibilities ?
    Many Thanks
    Laurent

    Hi,
    You can create the activity by double clicking on appointment calendar.
    Go to Tcode : crmd_order and select calendar tab.Double click on any time of the calendar and select the appropriate transaction type for activity.
    Then you will be able to create the activity.
    If helpful kindly reward me.
    Thanks & Regards,
    Anirban

Maybe you are looking for

  • Warning messages from ME_PROCESS_REQ_CUST  method CHECK

    Hello All, I am facing below mentioned issue with BADI ME_PROCESS_REQ_CUST 1: how can we issue warning messages from BADI ME_PROCESS_REQ_CUST method CHECK? 2: Check method is called twice if I click on check button in ME52N. Thanks

  • Using Get Data From Aggregation event class in SQL Profiler - SSAS 2012

    Hi, I'd like to understand better the use of the Get data from aggregation event class in SQL Profiler to monitor a MDX query and which info provide. Fe, does it return the MDX query? Is it possible to use this event class in order to monitor MDX que

  • How to write the Business Process

    Can anybody please give me the link on How to write the Business Process for <b>IC_C03</b>... we have done the blue print and going to write the documentation for this info provider. So please provide the related links..........

  • 2602I stand alone to LWAP conversion

    Is it possible to convert  AIR-SAP2602I to LWAP? I want to connect it to the WLC 5508 via flex ctonnect mode. What all are the LWAP models supported by the WLC 5508. I couldn't find these details in 5508 data sheet

  • Migrating reports sets to another database

    Does anyone know if there is an way to copy request sets from one database to another (for program promotion into production) without having to re-enter them? thanks