Dynamic creation of objects at runtime

supposed i want to create a tree structure and i use objects to represent the nodes...but i need the user to specify the number of nodes in the tree...so the user will enter 10 or 13 whatever.So how do we create those nodes dynamically...i know how to add nodes ...umm Example
Node A=new node('A');
Node B=new node('B');
//this creates a new node A of type node(user defined class)
but how to create it dynamicaaly
eg
for(i=1;i<=Totalnodes;i++)
Node A= new node('A');
} //well obviously this code is wrong .
Here is a copy of the main program where nodes are added to the code and not specified by the user
public class Main {
     public static void main(String[] args)
          //Lets create nodes as given as an example in the article
          Node nA=new Node('A');
          Node nB=new Node('B');
          Node nC=new Node('C');
          Node nD=new Node('D');
          Node nE=new Node('E');
          Node nF=new Node('F');
          //Create the graph, add nodes, create edges between nodes
          Graph g=new Graph();
          g.addNode(nA);
          g.addNode(nB);
          g.addNode(nC);
          g.addNode(nD);
          g.addNode(nE);
          g.addNode(nF);
          g.setRootNode(nA);
          g.connectNode(nA,nB);
          g.connectNode(nA,nC);
          g.connectNode(nA,nD);
          g.connectNode(nB,nE);
          g.connectNode(nB,nF);
          g.connectNode(nC,nF);
.

Ugh i so messed up..ok ok im gonna explain clearly now coz i just kinda blurted out stuff before :P
ok So here is the main program :
public class Main {
     public static void main(String[] args)
          //Lets create nodes as given as an example in the article
          Node nA=new Node('A');
          Node nB=new Node('B');
          Node nC=new Node('C');
          Node nD=new Node('D');
          Node nE=new Node('E');
          Node nF=new Node('F');
          //Create the graph, add nodes, create edges between nodes
          Graph g=new Graph();
          g.addNode(nA);
          g.addNode(nB);
          g.addNode(nC);
          g.addNode(nD);
          g.addNode(nE);
          g.addNode(nF);
          g.setRootNode(nA);
          g.connectNode(nA,nB);
          g.connectNode(nA,nC);
          g.connectNode(nA,nD);
          g.connectNode(nB,nE);
          g.connectNode(nB,nF);
          g.connectNode(nC,nF);
          //Perform the traversal of the graph
          System.out.println("DFS Traversal of a tree is ------------->");
          g.dfs();
          System.out.println("\nBFS Traversal of a tree is ------------->");
          g.bfs();
And this is the Graph module:
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class Graph
     public Node rootNode;
     public ArrayList nodes=new ArrayList();
     public int[][] adjMatrix;//Edges will be represented as adjacency Matrix
     int size;
     public void setRootNode(Node n)
          this.rootNode=n;
     public Node getRootNode()
          return this.rootNode;
     public void addNode(Node n)
          nodes.add(n);
     //This method will be called to make connect two nodes
     public void connectNode(Node start,Node end)
          if(adjMatrix==null)
               size=nodes.size();
               adjMatrix=new int[size][size];
          int startIndex=nodes.indexOf(start);
          int endIndex=nodes.indexOf(end);
          adjMatrix[startIndex][endIndex]=1;
          adjMatrix[endIndex][startIndex]=1;
     private Node getUnvisitedChildNode(Node n)
          int index=nodes.indexOf(n);
          int j=0;
          while(j<size)
               if(adjMatrix[index][j]==1 && ((Node)nodes.get(j)).visited==false)
                    return (Node)nodes.get(j);
               j++;
          return null;
     //BFS traversal of a tree is performed by the bfs() function
     public void bfs()
          //BFS uses Queue data structure
          Queue q=new LinkedList();
          q.add(this.rootNode);
          printNode(this.rootNode);
          rootNode.visited=true;
          while(!q.isEmpty())
               Node n=(Node)q.remove();
               Node child=null;
               while((child=getUnvisitedChildNode(n))!=null)
                    child.visited=true;
                    printNode(child);
                    q.add(child);
          //Clear visited property of nodes
          clearNodes();
     //DFS traversal of a tree is performed by the dfs() function
     public void dfs()
          //DFS uses Stack data structure
          Stack s=new Stack();
          s.push(this.rootNode);
          rootNode.visited=true;
          printNode(rootNode);
          while(!s.isEmpty())
               Node n=(Node)s.peek();
               Node child=getUnvisitedChildNode(n);
               if(child!=null)
                    child.visited=true;
                    printNode(child);
                    s.push(child);
               else
                    s.pop();
          //Clear visited property of nodes
          clearNodes();
     //Utility methods for clearing visited property of node
     private void clearNodes()
          int i=0;
          while(i<size)
               Node n=(Node)nodes.get(i);
               n.visited=false;
               i++;
     //Utility methods for printing the node's label
     private void printNode(Node n)
          System.out.print(n.label+" ");
And this is the node module:
public class Node
     public char label;
     public boolean visited=false;
     public Node(char l)
          this.label=l;
So my question is: How do i get the user to specify the number of nodes..i.e take input the number of nodes...add them to a tree....and how do i convert this graph into a tree

Similar Messages

  • Dynamic creation of object

    Hai
    There is a calss Firm like below
    public class Firm
    public void sayHai()
    System.out.println("Hai");
    There is a main class like below
    public main
    public void getObject(String className,Object firmObject)
    In this method I am passing Object as a parameter.
    I want to accessw sayHai() method of Firm Class by using firmObject
    variable.
    Actually i am trying like below
    Class clsFirm = Class.forName(className);
    Object objFirm = clsFirm.newInstance();
    objFirm.sayHai(); // Here it is showing error. I am not getting
    // How to cast the ObjFirm to actual object.
    // Since I know className only.
    public static void main(String args[])
              Main doMain = new Main();
    Firm doFirm = new doFirm();
              dc.getObject("Firm",doFirm);
    Thnks in advance for clarifying my doubt.

    There are two approaches. Usually the best one is to predefine an interface which your dynamically loaded are required to implement. Then you can cast the dynamically created object to that interface and call it from there.
    public interface DynInterface {
      public void sayHI();
    public class Firm implements DynInterface {
      public void sayHi() {
    Class cls = Class.forName("Firm");
    DynInterface obj = (Dyninterface)cls.newInstance();
    obj.sayHi();If you don't have that kind of control over the specs of the dynamically loaded classes they you need to resort to introspecion. In this can use the getMethod() call of Class to get a java.lang.reflect.Method object and use "invoke" on it:
    Class cls = Class.forName("Firm");
    Method m = cls.getMethod("sayHi", null);
    Object obj = cls.newInstance();
    m.invoke(obj, null);

  • Dynamic Creation of Objects using Tree Control

    I am able to Create Dynamic Objets using List control in
    flex,but not able to create objects using TreeControl,currently iam
    using switch case to do that iam embedding source code please help
    me how to do that
    <?xml version="1.0" encoding="utf-8"?>
    <!--This Application Deals With How to Create Objects
    Dynamically -->
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:XML id="treeDP">
    <node label="Controls">
    <node label="Button"/>
    <node label="ComboBox"/>
    <node label="ColorPicker"/>
    <node label="Hslider"/>
    <node label="Vslider"/>
    <node label="Checkbox"/>
    </node>
    </mx:XML>
    <mx:Script>
    <![CDATA[
    import mx.core.UIComponentGlobals;
    import mx.containers.HBox;
    import mx.controls.*;
    import mx.controls.VSlider;
    import mx.controls.Button;
    import mx.controls.Alert;
    import mx.core.UIComponent;
    import mx.controls.Image;
    import mx.managers.DragManager;
    import mx.events.DragEvent;
    import mx.controls.Tree;
    import mx.core.DragSource
    import mx.core.IFlexDisplayObject;
    /*This function accepts the item as on when it is dragged
    from tree Component */
    private function ondragEnter(event:DragEvent) : void
    if (event.dragSource.hasFormat("treeItems"))
    DragManager.acceptDragDrop(Canvas(event.currentTarget));
    DragManager.showFeedback(DragManager.COPY);
    return;
    else{
    DragManager.acceptDragDrop(Canvas(event.currentTarget));
    return;
    /*This Function creates objects as the items are Dragged
    from the TreeComponent
    And Creates Objects as and When They Are Dropped on the
    Container */
    private function ondragDrop(event:DragEvent) : void
    if (event.dragSource.hasFormat("treeItems"))
    var items:Array =event.dragSource.dataForFormat("treeItems")
    as Array;
    for (var i:int = items.length - 1; i >= 0; i--)
    switch(items
    [email protected]())
    case "Button":
    var b:Button=new Button();
    b.x = event.localX;
    b.y = event.localY;
    b.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    myCanvas.addChild(b);
    break;
    case "ComboBox":
    var cb:ComboBox=new ComboBox();
    myCanvas.addChild(cb);
    cb.x = event.localX;
    cb.y = event.localY;
    cb.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "ColorPicker":
    var cp:ColorPicker=new ColorPicker();
    myCanvas.addChild(cp);
    cp.x = event.localX;
    cp.y = event.localY;
    cp.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "Vslider":
    var vs:VSlider=new VSlider();
    myCanvas.addChild(vs);
    vs.x = event.localX;
    vs.y = event.localY;
    vs.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "Hslider":
    var hs:HSlider=new HSlider();
    myCanvas.addChild(hs);
    hs.x = event.localX;
    hs.y = event.localY;
    hs.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    case "Checkbox":
    var check:CheckBox=new CheckBox();
    myCanvas.addChild(check);
    check.x = event.localX;
    check.y = event.localY;
    check.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    break;
    else {
    var Component:UIComponent =
    event.dragSource.dataForFormat("items") as UIComponent ;
    Component.x = event.localX;
    Component.y = event.localY;
    Component.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
    myCanvas.addChild(Component);
    /*How to move the Objects within the Container */
    public function mouseMoveHandler(event:MouseEvent):void{
    var
    dragInitiator:UIComponent=UIComponent(event.currentTarget);
    var ds:DragSource = new DragSource();
    ds.addData(dragInitiator,"items")
    DragManager.doDrag(dragInitiator, ds, event);
    ]]>
    </mx:Script>
    <mx:Tree dataProvider="{treeDP}" labelField="@label"
    dragEnabled="true" width="313" left="0" bottom="-193" top="0"/>
    <mx:Canvas id="myCanvas" dragEnter="ondragEnter(event)"
    dragDrop="ondragDrop(event)" backgroundColor="#DDDDDD"
    borderStyle="solid" left="321" right="-452" top="0"
    bottom="-194"/>
    </mx:Application>
    iwant to optimize the code in the place of switch case
    TextText

    Assuming your objects are known and what you need are simply
    variable names created by the program, try using objects as
    associative arrays:
    var asArray:Object = new Object();
    for (var n:int = 0; n < 10; n++) {
    asArray["obj" + n] = new WHAT_EVER();

  • Dynamic creation of class at runtime

    I need to be able to dynamically create an instance of a
    class that isn't known until runtime - actually based on the
    filename
    so in my fla:
    var className:String="Test"; /* code to get a class name
    derived from the filename */
    var obj = new [className]();
    trace(obj);
    the code above only works if i put the literal directly in [
    like so:
    var obj = new ["Test"]();
    is there a way to do this???
    Any help much appreciated
    cheers Steve

    This might help you out:
    http://dynamicflash.com/2005/03/class-finder/
    "steveanson" <[email protected]> wrote in
    message
    news:e3fcnv$6c7$[email protected]..
    > I need to be able to dynamically create an instance of a
    class that isn't
    known
    > until runtime - actually based on the filename
    >
    > so in my fla:
    > var className:String="Test"; /* code to get a class name
    derived from
    the
    > filename */
    > var obj = new ();
    > trace(obj);
    >
    > the code above only works if i put the literal directly
    in
    > like so:
    > var obj = new ();
    >
    > is there a way to do this???
    > Any help much appreciated
    > cheers Steve
    >
    >
    >

  • Dynamic Creation of Items in Runtime through Application UI

    We have a requirement where the Users wanted to have an option of creating an item dynamically. We developed and deployed a very simple application but the users want to have the flexibility of adding new columns (without vaildations and processing - just data) to some of the existing regions. They are not IT people and want a simple interface to add columns without IT involvement.
    I thought of two options.
    (a) To pre-create around 10 items in the table with column names as customize1...customize10 with varchar2(1000). Have a configuration table which stores the column names and Label. Create a Report based on a Pl/SQL function returning query, and using HTMLDB_ITEM to dynamically populate them. Iam not very keen about this approach as do not want to create unnecessary columns and have to do a lot of manual processing for the data manipulation.
    a.1. Can we create a form (not a report) based on a pl/Sql function returning query.
    (b) To have an interface which does an "Alter Table .... add column ...." to create the new column. In this case how can we include this column to an existing form. Can we use HTMLDB_ITEM to add (create) columns to an existing region?
    (c) Any other suggestion ?
    Would appreciate an answer on the way to go forward to this, and also to a.1.
    Thanks

    Hi Marc,
    Thanks. I just tried something like this. Taking the EMP table example, (it doesn't matter which table), I created a region based on a Pl/Sql function returning SQL query
    ( I selected the vertical report template including nulls to display it like a form ) :
    DECLARE
    v_sql VARCHAR2(3000) ;
    mn_idx NUMBER := 1 ;
    BEGIN
    v_sql := 'SELECT ' ;
    FOR recs IN (SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'EMP' ORDER BY COLUMN_ID)
    LOOP
    v_sql := v_sql || 'HTMLDB_ITEM.TEXT(' || mn_idx || ',' ||
    recs.column_name || ') ' || recs.column_name || ', ' ;
    mn_idx := mn_idx + 1 ;
    END LOOP ;
    v_sql := SUBSTR(v_sql, 1, LENGTH(v_sql) -2) ;
    v_sql := v_sql || ' FROM EMP WHERE EMPNO = 7369 ORDER BY 1 ' ;
    RETURN v_sql ;
    END ;
    This allowed me to do my updates etc.., Then I created a button called 'Apply' and a process called 'update_changes' on button click and defined this:
    DECLARE
    v_sql varchar2(1000) ;
    mn_ctr NUMBER := 1 ;
    BEGIN
    v_sql := 'BEGIN UPDATE EMP SET ' ;
    FOR recs IN (select COLUMN_ID, COLUMN_NAME, DATA_TYPE
    from all_tab_columns where table_name = 'EMP'
    ORDER BY COLUMN_ID) loop
    -- Make changes here if required- this is assuming 9 columns --
    v_sql := v_sql || recs.column_name || ' = HTMLDB_APPLICATION.G_F0' || mn_ctr || '(1),' ;
    mn_ctr := mn_ctr + 1;
    end loop ;
    v_sql := substr(v_sql, 1, length(v_sql) - 1) ;
    v_sql := v_sql || ' WHERE EMPNO = 7369; END ;' ;
    execute immediate (v_sql) ;
    END ;
    Since this is for example, I didn't include code for Checksum and hardcoded empno = condition and have provision for 9 columns. I made some changes and tried saving it and I was able to do it.
    I altered the table to add a column / drop a column and when I relogin, Iam able to see the changes.
    Can you tell me if there could be any drawbacks in this approach ?.

  • Dynamic creation of object names

    Dear all,
    I have chose a rather generic title for a rather special problem, since I believe the above is the root. I am trying to create a bunch of JButtons which should have a running number in their names, like: button1, button2, button3, etc. Naturally, I'd like to do this in a loop. But it seems like I can't just concatenate the loop index to the button name like this:
    for(int i = 0; i < x; i++)
          JButton myButton + i = new JButton("Text");
        }How else could I achieve this? Thanks a lot in advance for any hitns!
    Cheers,
    N.

    Sorry for checking back so late...got distracted.
    To clarify further: I want to populate a column in a JTable with the buttons. The table rows contain pairs of words for a simple vocabulary trainer. If the user clicks on the button, the respective row should be deleted. The table data is built in a loop that populates a 2-dimensional object array. So, the buttons need some sort of identifier associated with them, so that I can determine which row should be deleted.
    Cheers,
    N.

  • Dynamic creation of ComponentUsage

    Hi people,
    I want to reuse a view (ViewA) in different views (ViewB, ViewC, ViewD).ViewA has a quite complex logic, so it is necessary to outsource this view.  Not only the logic, but also the count of UIElements and contextelements is quite large, for this I don't want to implement this part redundant in the views A, C and D.
    I have to use ViewA in a table in  the TablePopin UIElement. Every line of the table should have its own instance of ViewA. Is that possible?
    My idea is it, to put the view in an own component. For every tableline I need an instance of the componentUsage. My problem is now, that I'm not able to create at runtime a ComponentUsage and at designtime I don't know how many instances I need. Is it possible in webdynpro to create dynamic instances of ComponentUsage?
    If you know an other way, that prevents me from implementing the view and its logic more times, please tell me!
    Thanks in  advance,
    Thomas Morandell

    Hi Thomas,
    just for clarification. Principally it is possible in Web Dynpro to dynamically create new component usages of the same type like an existing, statically declared one. This means after having defined a component usage of type ISomeComp (component interface definition) you can dynamically create new component usages which all point to the same component interface definition ISomeComp:
    wdThis.wdGetISomeCompUsage().createComponentUsageOfSameType();
    But this dynamic creation approach implies, that you must also embed the component interface view of this component usage to the view composition dynamically; and this is (unfortunately) quite cumbersome and complicated based on the existing Web Dynpro Java API (it is not yet optimized for a simple dynamic view composition modification.
    Additionally, like Valery pointed out, the dynamic creation of new component usages is not compatible with table popins.
    Regards, Bertram

  • Creating and compiling JavaFX objects at runtime

    I am interested in the possibility of creating JavaFX objects at runtime where their definition is not know until runtime and am unsure about how to do this. Clearly I will need the JavaFX Script compiler at runtime which I guess is not that much of a problem but I am looking to accomplish this within the browser context so it would mean that I need the compiler to be available as part of the standard JRE much in the same way as the JavaFX Script interpreter is to obviate the need for it to be downloaded.
    Does anyone know if the JavaFX Script compiler is available as a built-in component within the latest versions of the JRE? If not, is it planned to include it in the future (JSE 7 perhaps)?
    Thanks,
    The Gibbon

    Perhaps the thread [Dynamic Scripting, how?|http://forums.sun.com/thread.jspa?threadID=5379268] can help.

  • How can I trace creation of objects?

    I am wondering how I can trace creation of objects with new. For example:
    interface CreationListener {
        void objectCreated(Object o);
    class CreationNotifier {
        static void registerCreationListener(Class cls, CreationListener listener) {
            // registers `listener' to be notified after creating any object of class `cls'
    class Test {
        public static void main(String[] args) {
            CreationNotifier.registerCreationListener(Integer.class, new CreationListener() {
                public void objectCreated(Object o) {
                    System.out.println("Created Integer " + ((Integer)o).intValue());
            new Integer(2);  // Now I would expect to see `Created Integer 2' on my console...
    }In other ways I want to get informed about every object of the specified class that gets created
    throughout the application.
    Does anyone have an idea about it? I was trying to find something appropriate in SecurityManager
    but I failed :(
    Please help!

    I think you did not understand exactly what I meant. Your solution is only good for classes written by
    me and I wanted to catch all object constructions in any class, e.g. one that I have only in a binary form.
    Maybe Hashtable is
    not the right data structure but I got to go back to
    work :-) Let me know if you come up with a better
    implementation.
    -- Niladri.I created a WeakHashSet class on top of WeakHashMap which uses one static object as a value and really cares only about the keys. In the registrating class I have a HashMap with keys of type Class and values of WeakHashSet. The register method is simple:
    public void register(Object o) {
        if (o == null) return;
        if (!map.containsKey(o.getClass()))    // this is the first object of this class being registered
            map.put(o.getClass(), new WeakHashSet());
        ((WeakHashSet)map.get(o.getClass())).add(o);    // WeakHashSet implements Set interface
    }This design ensures (because of using WeakHashMap) that I only have live objects in my structure after running GC (in fact, I call System.gc() in methods to find the live objects of a specific class).
    As you can see, my only problem is to have the object registration automate for classes that I have not written (and do not have sources).
    And using the profiler is not portable (as I guess) - in examples for JProbe they used DLL's and UNIX shared objects. And that requires unusual switches when starting JVM. I would like to have an all-Java language solution as the code fragments which I have described come from a library which I am writing now and I should not make the users of it depend on switches or dynamic libraries...
    Anyway, thanks for your good will. :-)

  • Events from dynamically created CNiGraph object

    Hi,
    My application requires me to create a variable number of CNiGraph objects at runtime. I'm plotting data from a file and I don't know in advance how many variables there will be. So, I'm dynamically creating the graph objects in the OnInitDialog() method of my CView derived class. The thing I'm stuck on is how to get the various messages from the graph when it is created dynamically like this. I can't use Class Wizard for the message maps because the number is variable. I suppose I could create a bunch of static message maps (more than I think I would ever need), but is there a cleaner way to do this? I'm using Visual C++ 6.0.
    Thanks, Bob

    Ok, I figured it out. You need to change the event sink map to use the ON_EVENT_RANGE instead of ON_EVENT. The help for ON_EVENT_RANGE tells you all you need to know.

  • Re: (forte-users) Dynamic construction of objects at runtimeusing str

    Shirish,
    We are currently doing this using libraries. It works something like this:
    Create your classes, have them implement interfaces and build them into a
    library. Then we have the following
    method 1 basically does a findlibrary to load the library:
    self.Lib = task.part.FindLibrary( projectName = 'MyLib',
    distributionId = 'mylib',
    compatibilityLevel = 1,
    libraryName = 'mylib');
    method 2 is called to load the dynamic object does a findclass and returns
    an object which implements a known interface.
    GetClass (pClassName string): object
    begin
    return self.MessageLibrary.FindClass(classname = pClassName);
    end;
    aObj : MyObjInterface;
    aObj = (MyObjInterface)(GetClass('DynamicClassName'));
    HTH
    Michael
    At 23:28 18/10/1999 MDT, you wrote:
    --Does anybody have information about how to create objects at runtime using a
    string that contains the classname?
    --You have an object of the base class and you have a string containing the
    derivedclass name, how do you do the typecasting of the base calss object
    using this string?
    please send anyinformation about the following question to
    [email protected]
    Thank you!!!
    shirish****************************************************************************
    Michael Burgess Ph: +61 2 9239 4973
    Contract Consultant Fax: +61 2 9239 4900
    Lawpoint Pty. Limited E-mail [email protected]
    ****************************************************************************

    Shirish,
    We are currently doing this using libraries. It works something like this:
    Create your classes, have them implement interfaces and build them into a
    library. Then we have the following
    method 1 basically does a findlibrary to load the library:
    self.Lib = task.part.FindLibrary( projectName = 'MyLib',
    distributionId = 'mylib',
    compatibilityLevel = 1,
    libraryName = 'mylib');
    method 2 is called to load the dynamic object does a findclass and returns
    an object which implements a known interface.
    GetClass (pClassName string): object
    begin
    return self.MessageLibrary.FindClass(classname = pClassName);
    end;
    aObj : MyObjInterface;
    aObj = (MyObjInterface)(GetClass('DynamicClassName'));
    HTH
    Michael
    At 23:28 18/10/1999 MDT, you wrote:
    --Does anybody have information about how to create objects at runtime using a
    string that contains the classname?
    --You have an object of the base class and you have a string containing the
    derivedclass name, how do you do the typecasting of the base calss object
    using this string?
    please send anyinformation about the following question to
    [email protected]
    Thank you!!!
    shirish****************************************************************************
    Michael Burgess Ph: +61 2 9239 4973
    Contract Consultant Fax: +61 2 9239 4900
    Lawpoint Pty. Limited E-mail [email protected]
    ****************************************************************************

  • Error in creation of Object Type from XML passed

    Hi,
    I am facing a problem creating a appropriate a object type for a XML.
    Below are the details:
    XML Passed
    <mer_offer_action_data>
    <form_id>
    134039588
    </form_id>
    <action_cd>
    OA
    </action_cd>
    <offer_decline_reason_cd>
    </offer_decline_reason_cd>
    <start_dt>
    </start_dt>
    <candidate>
    <ds_prs_id>
    109315
    </ds_prs_id>
    <ds_prs_id>
    110534
    </ds_prs_id>
    <ds_prs_id>
    110059
    </ds_prs_id>
    </candidate>
    </mer_offer_action_data>
    Types Declaration
    +CREATE OR REPLACE type MER_OFF_CANDIDATE
    AS
    OBJECT
    DS_PRS_ID NUMBER
    CREATE OR REPLACE TYPE MER_OFF_CANDIDATE_t
    AS
    TABLE OF MER_OFF_CANDIDATE;
    CREATE OR REPLACE type MER_OFFER_ACT_DATA
    AS
    OBJECT
    FORM_ID NUMBER,
    ACTION_CD VARCHAR2(6),
    OFFER_DECLINE_REASON_CD VARCHAR2(6),
    START_DT VARCHAR2(11),
    CANDIDATE MER_OFF_CANDIDATE_t
    CREATE OR REPLACE TYPE MER_OFFER_ACT_DATA_t
    AS
    TABLE OF MER_OFFER_ACT_DATA;
    CREATE OR REPLACE type MER_OFFER_ACTION_DATA
    AS
    OBJECT
    MER_OFF_ACT_DATA MER_OFFER_ACT_DATA_t
    /+
    My Declaration
    +merOffActDataXML      xmltype;
    merOffActData     MER_OFFER_ACTION_DATA := MER_OFFER_ACTION_DATA(MER_OFFER_ACT_DATA_t());+
    Inside Pl/SQL block
    +-- Converts XML data into user defined type for further processing of data
    xmltype.toobject(merOffActDataXML,merOffActData);+
    when I run the Pl/Sql block it gives me error
    ORA-19031: XML element or attribute FORM_ID does not match any in type ORADBA.MER_OFFER_ACTION_DATA
    which means the object type mapping is wrong
    I would like to know whether the object type I had created is correct or not.
    Thanks for your help
    Beda

    Bedabrata Patel wrote:
    Below are the details:The details except for a description of the problem
    I am facing a problem creating a appropriate a object type for a XML.And which error you are getting
    Error in creation of Object Type http://download.oracle.com/docs/cd/E11882_01/server.112/e10880/toc.htm
    And which version of Oracle you are getting the unknown error creating the unknown problem.

  • Error in creation of Object Type

    Hi,
    I am facing a problem creating a appropriate a object type for a XML.
    Below are the details:
    XML Passed
    <mer_offer_action_data>
         <form_id>
              134039588
         </form_id>
         <action_cd>
              OA
         </action_cd>
         <offer_decline_reason_cd>
         </offer_decline_reason_cd>
         <start_dt>
         </start_dt>
         <candidate>
              <ds_prs_id>
                   109315
              </ds_prs_id>
              <ds_prs_id>
                   110534
              </ds_prs_id>
              <ds_prs_id>
                   110059
              </ds_prs_id>
         </candidate>
    </mer_offer_action_data>
    Types Declaration
    +CREATE OR REPLACE type MER_OFF_CANDIDATE
    AS
    OBJECT
    DS_PRS_ID NUMBER
    CREATE OR REPLACE TYPE MER_OFF_CANDIDATE_t
    AS
    TABLE OF MER_OFF_CANDIDATE;
    CREATE OR REPLACE type MER_OFFER_ACT_DATA
    AS
    OBJECT
    FORM_ID NUMBER,
    ACTION_CD VARCHAR2(6),
    OFFER_DECLINE_REASON_CD VARCHAR2(6),
    START_DT VARCHAR2(11),
    CANDIDATE MER_OFF_CANDIDATE_t
    CREATE OR REPLACE TYPE MER_OFFER_ACT_DATA_t
    AS
    TABLE OF MER_OFFER_ACT_DATA;
    CREATE OR REPLACE type MER_OFFER_ACTION_DATA
    AS
    OBJECT
    MER_OFF_ACT_DATA MER_OFFER_ACT_DATA_t
    /+
    My Declaration
         +merOffActDataXML          xmltype;
         merOffActData          MER_OFFER_ACTION_DATA := MER_OFFER_ACTION_DATA(MER_OFFER_ACT_DATA_t());+
    Inside Pl/SQL block
         +-- Converts XML data into user defined type for further processing of data
         xmltype.toobject(merOffActDataXML,merOffActData);+
    Thanks for your help
    Beda
    Edited by: Bedabrata Patel on Jul 12, 2010 5:51 AM

    Bedabrata Patel wrote:
    Below are the details:The details except for a description of the problem
    I am facing a problem creating a appropriate a object type for a XML.And which error you are getting
    Error in creation of Object Type http://download.oracle.com/docs/cd/E11882_01/server.112/e10880/toc.htm
    And which version of Oracle you are getting the unknown error creating the unknown problem.

  • Error in Creation of Object ID 00000000 is not allowed

    Hi all,
    When I am Hiring an employee using PA40, I am getting an error as "Creation of Object ID 00000000 is not allowed", when I save it.
    In the NUMKR Feature, the return value has been assigned to the Personnel Sub Area.
    Pls. can anybody explain, how can I solve this problem. 
    This is urgent requirement of client.
    Thanks,
    HR User.

    Hi Hr user
    Now listen carefully.
    1. If you have defined your feature NUMKR according to PSA then while running hiring action does PSA comes or it just gives you the Position, PA, EG and ESG fileds only.
    2. If the first condition is true then you will get the error, now the question is why
    Answer, you have defined the feature through PSA and once you try to save the IT0000 there is no PSA mentioned there thats why the system gives you the error.
    If this explnanation is understood by you than reply , i will tell you how you can bring the PSA field also in hiring action at IT0000.
    Do reply
    Regards,
    Bhupesh Wankar

  • How do I create multiple objects during runtime?

    I don't know how to create multiple objects during runtime, here's my problem:
    I get a String as input. Then I create an object called newobject. I put the object in a hashtable with the above string as key.
    Then comes the problem, in order to create a new object, I have to rerun the same class, which uses the same name (newobject) to create a 2nd object. Now my hashtable doesn't reference to my 1st object anymore...
    Is there anyway I can fill up the hashtable with different objects, and make each key point to each object it was supposed to?
    For those who want to see a bit of the program:
    public class PlayBalloon{
    public Hashtable ht = new Hashtable();
    for(){
    Balloon pB = newBalloon;
    newBalloon=new Balloon(pB);
    ht.put("Some input from user", newBalloon);
    for(){
    ht.get(s).draw;<= s=string, draw=own meth. in Balloon
    }

    I think i can see the problem that you are having. You have, in effect, duplicate keys in your hashtable - ie, two strings used as keys with the same name.
    The way that a hashtable works is as follows...
    When you ask for a value that is mapped to a key it will go through the table and return the first occurence it finds of the key you asked for. It does this by using the equals() method of whatever object the key is (in your case it is a String).
    If you cant use different Strings for your keys in your hashtable then i would consider writing an ObjectNameKey class which contains the String value that you are trying to put in the hashtable and an occurrence number/index or something to make it unique. Remember to override the equals method in your ObjectNameKey object or else the hash lookup will not work. For example
    class ObjectNameKey {
        private String name;
        private int occurence;
        public ObjectNameKey(String name, int occ) {
            this.name = name;
            this.occurence = occ;
        public String getName() {
            return name;
        public String getOccur() {
            return occurence;
        public boolean equals(Object o) {
            if (!(o instanceof ObjectNameKey)) {
                return false;
            ObjectNameKey onk = (ObjectNameKey)o;
            if (onk.getName().equals(name) && onk.getOccur() == occurence) return true;
            return false;

Maybe you are looking for