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;

Similar Messages

  • How to create multiple objects within a class

    I have a item.lvclass which has an item.ctl (contains a cluster of class private data).  I need to add another object (item2.ctl) within that same class so that I can reuse the code for that class.
    So how do you create additional objects within the same class?

    Well... right now...  I've cornered myself going down this path:  http://forums.ni.com/t5/LabVIEW-Idea-Exchange/LVOO​P-Interfaces/idc-p/1314637#M8918
    Seems like the solution in the idea was not implemented yet....
    Okay.  I will try to describe the situation differently...
    Let's say I have a Car.lvclass
    I want to have two objects:  sedan & roadster
    both have similar properties, but also have different properties:
    4 doors vs 2 doors
    hardtop vs convertible
    silver vs white (color)
    I want the two objects to be of the same class so that they can share the same private and public VI's.  As a matter of fact, I want to have both objects in the VI's within the Car.lvclass.

  • Any ideas about creating persistant object during execution?

    As a newbie, I wrote a badly designed applet which is used to share different keys with different devices. Now I got a problem about if the number of devices increased, how to generate new key objects during the execution and store it as a persistant object. I would use a (short) variable to restrict the number of devices and I only know using JCSystem. Transaction to update a byte array. Does anyone has good ideas about this problem?

    Could you explain a little more detail about what you are trying to do? Are you allocating a certain amount of space for keys at install time and setting a limit to this or do you plan to allocate memory at runtime as new devices come along? Do you have some sample code to share that would clarify what you are trying to do?
    I would suggest creating all your data up front and tracking which keys are allocated.
    - Shane

  • How can I create a object for a note?

    Hi experts,
        I need to apply the note 501905 but when I try in the SNOTE transacction I receive this error:
    Object REPS Z_MRM_DELETE_PP does not exist; create it
    Diagnosis
    The SAP Note that you want to implement contains changes to an object that does not yet exist in your system.
    SAP Notes contain only changes to objects that already exist. This means that the the system cannot automatically create new objects during the implementation of this SAP Note.
    Procedure
    1. Cancel the SAP Note implementationl.
    2. Create an empty object REPS Z_MRM_DELETE_PP with the corresponding object editor.
    3. Restart the SAP Note implementation.
    How can I create that Object??
    Thanks for the help!

    Hi Carlos,
    It says that you have to create a new program with a name Z_MRM_DELETE_PP.
    Once you create and activate the program you can execute the SAP Note.
    All this processure will be written in the SAP Note.
    Please Go through the Note using below:
    Step1: Use T.code SNOTE.
    Step2: Use menu GOTO --> NOTE BROWSER. Provide the Note no and EXECUTE.
    Step3: Double click on the displayed line.
    Here you will get the information to do before implementing the note.
    Go through all the documentation, and once you did all the development given in the note then you can implement the note.
    Regards,
    Sreekanth.

  • How to update cgicmd.dat file during runtime?

    I'd like to know how do update cgicmd.dat file during runtime. For example, I run a report one.jsp as
    http://<machine>:<port>/reports/rwservlet?one.jsp&USERID=uid/pwd@db&DESTYPE=cache&mode=bitmap&desformat=htmlcss
    within this report there is a hyperlink to open another report named two.jsp.
    before creating this hyperlink, I'd like to update cgicmd.dat file with passed in userID, pwd, and connection, so two.jsp can use this key for userinfo
    so I can create hyperlink as follows
    srw.set_hyperlink('/reports/rwservlet?report=two.jsp'||
    '&cmdkey=userinfo&DESTYPE=cache&mode=bitmap&desformat=htmlcss');
    Thanks

    To my knowledge the cgicmd.dat is only read when the OC4J starts, so you would have to come up with another solution. Using Single-Sign-On (SSO) is quite a good idea, and it's there for cases like this.
    Regards,
    Martin Malmstrom

  • Updation problem while creating multiple objects from enterprise portal

    Hi All,
    From enterprise portal i am calling an RFC 'BAPI_PROJECT_MAINTAIN' to create objects .
    While trying to create multiple objects simultaneously it gives error "sapuser is currently using, can't be created".
    It seems like as i am creating multiple objects by calling RFC repeatedly , while the first one is not updated fully i am sending the second value to be processed.
    Pl. tell me how to overcome this. Do I need to add any sleep time in EP or any other method is there in SAP to overcome this situation.
    thanks
    sandeep

    Dear Sandeep,
    I have discussed this problem with EP team lead in my organisation, i have given your email id to him he will forward the solution on your id.
    If usefull reward points helpfull....
    Regards,
    Rajneesh Gupta

  • How do i creating multiple icloud accounts for one itunes account

    how do i creating multiple icloud accounts to access one itunes account?

    Perhaps you could explain a bit more what you want to do...
    iCloud accounts don't access an iTunes account.
    iTunes account is used to make purchases.

  • How do I create multiple live USBs of Operating systems to boot from on one flashdrive?

    How do I create multiple live USBs of Operating systems to boot from on one flashdrive?
    I am attempting to create multiple live USBs within one flashdrive so that i can boot various operating systems without having to buy multiple USb sticks. I am using a Mac OS X Snow Leopard 10.6.8 Operating System currently. I am using the Terminal provided by the OS.
    I would like to try Debian, Kali, Precise Puppy, and Sabayon- with one space left empty for whatever Linux OS I would like to try next. I have partitioned an 8GB flashdrive into the following sections:
    name of intended OS,     space allocated for it:
    1)Debian ........................1.32 GB
    2)Kali..............................2.61GB
    3)Precise Puppy..............163.7MB
    4)Sabayon.......................1.77GB
    5)TBD..............................2.14GB
    I have figured out how to change the .iso files of the operating systems into .img files with the following commands:
    hdiutil convert -format UDRW /path/to/input.iso -o /path/to/output.img
    a .img.dmg file is created, this is corrected in the next line of code *please note: I am a a very beginner at programming, and would greatly appreciate any help. Thank you!
    mv /path/to/output/file.img{.dmg,}
    This is where I started to get confused:
    I entered diskutil list to find the location of the partitions on my flashdrive, and this is the relevant section:
    /dev/disk1
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:     FDisk_partition_scheme                        *8.0 GB     disk1
       1:                 DOS_FAT_32 DEBIAN               1.3 GB     disk1s1
       2:                 DOS_FAT_32 KALI                    2.6 GB     disk1s2
       3:                 DOS_FAT_32 PRECISE            163.7 MB   disk1s3
       4:                 DOS_FAT_32 SABAYON           1.8 GB     disk1s5
       5:                 DOS_FAT_32 TBD                     2.1 GB     disk1s6
    This is the code I attempted to use and the subsequent result:
    charles-burtons-mac-mini:~ charlesburton$ sudo dd if=/Users/charlesburton/Desktop/debian-live-7.2-i386-gnome-desktop.img of=/dev/disk1s1 bs=1m
    dd: /dev/disk1s1: Resource busy
    *at this point I went to the Disk Utility GUi and unmounted only the DEBIAN partition, now back to the terminal*
    charles-burtons-mac-mini:~ charlesburton$ sudo dd if=/Users/charlesburton/Desktop/debian-live-7.2-i386-gnome-desktop.img of=/dev/disk1s1 bs=1m
    dd: /dev/disk1s1: end of device
    1259+0 records in
    1258+1 records out
    1320005632 bytes transferred in 1011.966891 secs (1304396 bytes/sec)
    Please may someone help explain why I had a return value of +1 in my records in and how I can make it work properly.

    I would like to know the answer to this as well.  I tried renaming the 3D version by adding 3D after it, but it still not a separate movie in iTunes.
    It's putting them in the same folder.

  • How can i create multiple accounts but use the same itunes?

    how can i create multiple accounts but use the same itunes?

    Hi iCloud is Making Me Go Crazy,
    You will need to create a new Apple ID for your GameCenter and iCloud services.  You can continue to use the current Apple ID you share with your Mom for access to iTunes Store purchases if you wish. 
    Using your Apple ID for Apple services
    http://support.apple.com/kb/HT4895
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/HT5622
    Cheers,
    - Judy

  • HT204053 how can i create multiple icloud accounts for my family members

    how can i create multiple icloud accounts for my family members

    Thanks...  I appreciate the reply.  Since I wrote the previous email, I actually went and changed my apple id (the main id) and the documentation I looked at said iCloud will set mail up automatically(?)...  I had it working before. 
    Also, I tried to manually set up the ID via the Mail Accounts screen(s) and I can't figure out what my server information is...  Pop or Imap?  What's the outgoing server and the incoming server?
    I typically have never had problems setting up mail accounts (in apple mail) with no problem.
    Can anyone point me in the right direction?
    Thanks in advance!

  • How can I create multiple versions of a video within the same project?

    OK...this is a probably a very basic question but I'm not sure how to word it clearly.
    How can I create multiple versions of a video within the same project? What I mean is that I have a bout 50 minutes of video and I want to make two DVDs using different clips from this original 50 minutes of footage. It would be a real pain to have to re-import the video AGAIN for the second DVD. I suppose I could drop anything I don't want to burn to DVD back into the clips pane but that would wipe out all my transitions wouldn't it? I want to save each project in their “raw” form so I can burn additional DVDs later otherwise I would just do them one at a time and not care about one of them being destroyed.
    Wow...that was a mess. Does anyone understand what the heck I’m asking? I hope so.

    How can I create multiple versions of a video within the same project?
    You can't. You make separate projects using the same or different clips, segments, transitions, titles, etc. You can even duplicate the first project and then modify/make the desired changes in the duplicated project. Each project can then be burned as a different DVD or as different titles on the same DVD if there is enough room.

  • How can I create multiple sales orders with reference to one contract?

    Hello Gurus,
    Can you please how can I create multiple sales orders with reference to one contract?
    thanks!
    Rakesh

    hi
    Lets consider example
    In your contract for line item 1 you have entered qty 100
    You careated sales order with 70 quantity, and now you want to creat another sales order for 30
    For this first you need to check what is your item category in contract (VA42)
    Goto VOV7
    SPRO - IMG  - Sales and distribution - Sales - Sales document item - Define item categories - Go to change mode
    Make the completion rule = B Item is completed after full quantity has been referenced

  • How can i create multiple versions of a photo in ios8?

    I Often want to create different versions of the same photo....with different crops, contrast, etc and keep them.  In iPhoto, that was done with the duplicate command, but there does not seem to be the same capability in ios8.  Any ideas?

    How can I create multiple versions of a video within the same project?
    You can't. You make separate projects using the same or different clips, segments, transitions, titles, etc. You can even duplicate the first project and then modify/make the desired changes in the duplicated project. Each project can then be burned as a different DVD or as different titles on the same DVD if there is enough room.

  • How do I create multiple calendars on my iPad?

    How do I create multiple calendars on my iPad?

    I love stealing another users posts and here is one now ....
    You don't create multiple calendars on the iPad.
    The iPad is designed to be synced with a supported application on your computer for contacts and calendar events. The contact Groups I've created with the Address Book on my Mac and the different calendars I have with iCal on my Mac are available and kept synchronized with the my iPhone's Contacts and Calendar applications, and the same applies to the iPad.
    Long story short, this is done with the supported application on your computer used for syncing contacts and calendar events.
    The same principle applies to PC users. You have to sync within iTunes from a supported calendar application on your PC.

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

Maybe you are looking for

  • Delivery document is in UOM bags but should be invoiced in kilos

    Hi Experts! Please help me on this matter. My client's situation is that a delivery document was created wherein the sales UOM is in bags and the unit price was in bags.  However, when the time of the invoicing came, the client's customer wants to be

  • Creative Live! Motion Supp

    I don't tend to post in newsgroups because I rarely feel I have anything worthwhile to input, but I feel this is pretty worthwhile. I've had Vista Ultimate RTM installed for some time now and whilst I was very pleased with it, I was unable to use it

  • Audio disabled when linked to port duplicator

    I am using Windows XP with my Thinkpad T400, and bought a Lenovo port duplicator model k33415 with my computer.  I have a keyboard and mouse attached to the port duplicator as well as a PDA sometimes. Whenever the port duplicator is attached to the c

  • Today's iTunes update has broken iTunes on Windows Server 2008 (64 Bit)

    After today's update, iTunes crashes 100% of the time upon launching. "iTunes has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available." is all the info the

  • I want to keep the bookmarks from my previous home page

    I was obliged to switch to Firefox. I knew from having it as my work browser that it was totally unfriendly to all the sites I visit (ironically, including the one that recommended it) but did it, anyway. Now all my bookmarked sites have vanished. Wh