Pulling Objects out of a Vector

Hi, all:
I am trying to pull Objects out of this vector, and the given method only wants to let me get integers. How do I go about getting Objects out of a vector like this one? The problem comes in with the last line, where the "get" method complains that it wants an integer. The API says the same; I just can't find a method that lets me pull an Object out of a vector instead of an integer. Any ideas?
          neighborList = new Vector();
          soldierNeighbors = new Vector();
          neighborList = world.getMooreNeighbors(x, y, false);
          for (int i = 0; i < neighborList.size(); i++){
          Soldier soldier = neighborList.get (soldier);

Soldier soldier = neighborList.get (soldier);You'll want to use "i" as your index, not "soldier", since you presumably want to get the soldier reference at element 'i'. Note that since you're not using generics, the get() method returns an Object reference. You'll need to cast it to Soldier. Example:
Soldier soldier = (Soldier) neighborList.get(i);Read more here: http://java.sun.com/docs/books/tutorial/collections/
~

Similar Messages

  • Specifying which Objects to pull out of a Vector

    I'm pulling certain objects out of a vector to play with them. My problem is that I only want certain ones. Inside the vector "neighborList when I getMooreNeighbors are objects other than Soldiers (there are Democrats, Monarchs, etc, etc). I only want to fiddle with the Soldiers. I'm getting an NPE when I get to the "get" method because I'm casting the objects as Soldiers when it's possible some aren't. What do I do? How do I only get the Soldiers out of the Vector?
    {code}
         public void getMyNeighbor () {
              neighborList = new Vector();
              soldierNeighbors = new Vector();
              neighborList = world.getMooreNeighbors(x, y, false);
              for (int i = 0; i < neighborList.size(); i++){
                   Soldier otherSoldier = (Soldier) neighborList.get (i);//NPE here
                   otherSoldier.getMyColor();
                   otherSoldier.getStrength();
              if (otherSoldier.getMyColor()!=this.getMyColor()){
                   fight();
    {code}

    So I think I tracked down that NPE, but another one seems to have cropped up. Is there a better way to write this? I'm asking my soldier to compare his color with the other guy and fight him if they don't match.
         public void getMyNeighbor () {
              neighborList = new Vector();
              soldierNeighbors = new Vector();
              neighborList = world.getMooreNeighbors(x, y, false);
              for (int i = 0; i < neighborList.size(); i++){
                   Object o = neighborList.get (i);
                   if (o instanceof Soldier) {
                        Soldier otherSoldier = (Soldier)o;
                        otherSoldier.getMyColor();
                        otherSoldier.getStrength();
              if (otherSoldier.getMyColor()!=this.getMyColor()){//NPE here
                   fight();
              }

  • Obtaining Row Clicked -- Pulling Hair Out

    I am working on a nice simple master detail. I have created a datatable and made one of the columns an action link. In the action handler for the link I attempt to get the row data from the dataTable object (to which the view is bound). However, I receive an illegal argument exception when I try to retrieve it. Depending on the various things I have tried I have either gotten an illegal cursor operation from oracle or this illegal argument exception. Also, all of the values for the individual element objects (like linkActionTexr or outputText) are null when they come to my action handler. So, how do I go about getting this information??? What am I missing??

    OK I have figured something out that appears to be part of the problem. Now, I just need a fix. The first time a click a link and go to the detail page I get an IllegalArgument Exception. What I am doing is in the acton for the link I store the getRowData (com.sun.jsfcl.data.DataCache.Row) in a session object. Then, on the next page, I pull values out of the map on that row and stuff them into fields. Is there some method or property that I need to set on the RowSetDataModel??
    Thanx,
    LES

  • I placed my ipad on top of my CPU with a music playing,i heard a crack on the sound and when i checked it,i can no longer hear a sound playing on my ipad.i tried to check place a headphone its still playing a sound but when i pull it out,wont play at all.

    i placed my ipad on top of my CPU with a music playing,i heard a crack on the sound and when i checked it,i can no longer hear a sound playing on my ipad.i tried to check place a headphone its still playing a sound but when i pull it out,wont play at all.

    I don't know if this will work but it's worth a try. I wonder if somehow you ended up with a short inside of your iPad. Give the things below are trying to see if that helps. Good luck.
    Try a Restart. 
    Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider. Press and hold the Sleep/Wake button until the Apple logo appears.
     Resetting your settings
    You can also try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your device settings again.... All of the settings in the settings app will have to be re-entered. You won't lose any data, but it takes time to enter all of the settings again.
    Resetting your device
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears. Apple recommends this only if you are unable to restart it.
    Or if this doesn't work and nobody else on the blog doesn't have a better idea you can contact Apple. 
    Here is a link to their contacts with most of the information below. 
    http://www.apple.com/contact/

  • I just tried to copy a folder to a pen drive from my mac. It transferred fine. I then ejected the pen drive then pulled it out. When I pulled it out it said it had not ejected correctly despite me just Doing this. The folder is now missing from both! Help

    I just copied a folder from my desktop to my pen drive. It transferred fine. I then ejected the pen drive then pulled it out. On doing so it said it had not been ejected properly!!!!! The folder is now missing from my computer and the pen drive. Pulling my hair out please help!

    When youi say Eject, the RAM copy of the Directory is written back to the drive. On a pen drive, this can take several seconds.
    If you get too excited and don't wait those few seconds, the directory write will be incomplete, and the drive will lose its integrity or lose files or both.

  • The other day I had to reset my phone because i pulled it out from my laptop when it was updating. I then tried to restore it but i clicked the wrong option and it has restored all of my stuff from 2 years ago, is there any way to get back the stuff I had

    The other day I had to reset my phone because i pulled it out from my laptop when it was updating. I then tried to restore it but i clicked the wrong option and it has restored all of my stuff from 2 years ago, is there any way to get back the stuff I had

    maggielou wrote:
    I thought that I had backed up my pictures to icloud, but when I looked online at icloud, I don't see pictures listed.  However, a few of the recent pictures have shown up on my phone.
    IHow could I get these from my MacBook to my phone?
    Thanks again.
    When you log into you icloud account on your computer you are viewing data that you sync to icloud not the backups.  You can't view the backups.
    Look at the two links I provided.
    You still didn't answer any of my two questions I asked.

  • HT4061 I am traveling from Ontario to BC and had my iPad in my bag and no banging or anything out of the ordinary and when I pulled it out I noticed it was cracked what can be done

    I'm traveling from Ontario to BC via car and had my iPad in my bag with me in the back seat? Nothing out of the usual stopping for gas and when I
    Pulled it out I noticed a huge crack and not sure what happen or what can be done please help

    Accidental damage is not covered by warranty.
    It will cost you approximately US$219.00 to US$299.00 depending on the model.
    Apple will replace the entire iPad; they don't repair.
    http://support.apple.com/kb/index?page=servicefaq&geo=United_States&product=ipad

  • Hi, I have a freecom 1TB hard drive which was working fine until it froze.  I pulled it out (mistake I now know) and now it doesn't mount.  It shows up in Disk Utility but won't manually mount.  When I try to repair it gives message 'failed on exit'.  hel

    Hi, I have a freecom 1TB hard drive which was working fine until it froze.  I pulled it out (mistake I now know) and now it doesn't mount.  It shows up in Disk Utility but won't manually mount.  When I try to repair it gives message 'failed on exit'. Some people have said to try Disk Warrior, but at $100 it's quite expensive maybe fix.  help!

    You likely need to reformat the drive which will destroy all data and you need a backup to restore it. If no backup is present then a data retrieval service can be more expensive than DiskWarrior. There is software that can rescue the data but I can not vouch for it's effectiveness as I have always maintained backups. .
    http://www.prosofteng.com/
    http://www.wondershare.net/ad/data-recovery-mac.html?gclid=CLTp3Mj07rkCFevm7AodL lUAHw
    http://diskdoctors.com/software/mac-data-recovery/utility.asp?gclid=CMyf_MH17rkC Fcvm7AodSE0A8A
    http://www.cleverfiles.com/

  • Pulling info out of service

    I found a quick cfc for creating a service in CF8:
    <cfcomponent>
    <cffunction name="sayHello" access="remote" hint="I say
    hi!" returntype="string">
    <cfargument name="to" hint="Whom to say hi to."
    required="false" default="world" type="string" />
    <cfreturn "Hello, #arguments.to#" />
    </cffunction>
    </cfcomponent>
    After I view the page (
    http://localhost:8500/TestingCF/service2.cfc?wsdl) it shows
    up with xml tags.
    My question is how do I pull info out of the xml tags into a
    user friendly view?

    what sort of 'user-friendly view' are you talking about?
    you want to present the ws structure details to the user?
    or you want the user to enter a name and receive "Hello,
    [name]!"
    response on the page?
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

  • I reinstalled my computer because it was too slow, and Safary icon has a ? question mark on it in the dock, i  pulled it out with the hope that  i can bring it back from the application, but the icon could not be found in the application. Pls help me.

    Could you pls help me? i reinstalled my computer and the Safari Icon has a ? mark on it in the dock, I pulled it out and it disappeared, I checked for this icon in the application folder but couldnt find it there.  So for me to go on Internet i have to open Firefox first. 2. The message Java Plug in has been disable appeared immediatle after the reinstallation. I need help from the community pls.

    Welcome to the Apple Support Communities
    I think that your Mac detects your hard disk, but the problem is that your new hard disk doesn't contain any operating system, so your Mac doesn't find any bootable partition and you see a question mark.
    If your Mac came with DVDs, insert the Mac OS X Install DVD and hold the C key while your Mac is starting. Then, just install Mac OS X. If the hard disk isn't prepared to install Mac OS X, you will have to erase it using "Mac OS Extended (Journaled)". See > http://pondini.org/OSX/DU1.html

  • Best Practices for pulling data out of Documentum (w/Crystal and Universe)

    I was curious to see if we had any best practices to see if we can pull data out of Documentum.
    Thanks
    Ian S

    None, use what works.

  • Objects out of alignment when published

    Hi,
    I;m having issues with alignment and have searched the forum bt not yet found a resolution.
    Despite setting alignment in the Design view, the live view places some objects out of alignment.
    See Kingsdown Holiday Homes - Self Catering Chalet Rental at Kingsdown Park, Kent | Home
    and the boxes as part of the left hand column are out. However in the Dutch version, they are not.
    thanks,
    Andrew

    Hi Michael,
    Thanks for taking the time to look and reply. I've checked and there are no overlapping or stray boxes, but its something I'll keep an eye out for. I grouped all the column items together, but this doesn't prevent it from happening.
    So this in Muse:
    is this live:
    unless I do this in Muse:
    which presents this live:
    Thanks for taking a look,
    Andrew

  • Getting an Object out of ArrayList

    Hello, I have a question about getting an Object out of an ArrayList. I have an object that's made up of four fields: name, average, total and position. Now, I need to read in values from a formatted text file, and stick those values into an array (the values correspond to the Object values), but since there's a variable number of items in the text file, I figured I could just use an ArrayList to store the objects, and when it's finished looping through the file, just copy the ArrayList items into my object. I have it working fine, except I can't seem to get the data in the ArrayList copied over to the array.
    I guess my question is simple: how can I copy over the ArrayList of objects into my object?
    Thanks very much for any help! :)

    Thanks a lot, I got it! After spending two hours on this problem, two lines of code fixed it for me. :P
    @Petes1234: Well basically because the data that's being read can have a variable length, I wanted to use an ArrayList to hold it temporarily. After it's done reading I have the size, so I guess that I wanted to extract the object data into a regular array so that it can be formatted and displayed to the user.
    Message was edited by:
    mistah-java

  • Saving image file as binary into database + pulling it out + displaying

    Hi guys, this is exactly I have to do, and have no ideal how to do.
    It will be greatly appreciated if you can offer help on this.
    I don't have a problem putting it into and pulling it out fo the database, it is really the jpg-> binary, and binary->display part that I need help on.
    Btw, I am currently using "draw Flatten PixMap.VI" to display a picture in labview, from a jpg file. Can I still use this VI to achieve what I intend to do?

    Have you tried this:
    Saving a binary file to a database with the Database Connectivity Toolset
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • Pulling photos out of finder for creating a slideshow

    Is it possible to pull photos out of the Finder to create a slideshow?

    On the machine on your signature yes.  You can use the Preview application to open all the photos in a folder, and create a slideshow once they have loaded.
    On a Classic Mac operating system from 14 years ago, I recommend using http://www.lemkesoft.com/ GraphicConverter, or the postcard ware:
    http://www.mac.org/graphics/jpegview/

Maybe you are looking for

  • IF-ELSE issue in Select Statement

    Hello, I have following query in SQL Server which I am trying to convert to Oracle 11g. IF '[Param.1]' = 'S' OR '[Param.1]' = 'T' THEN select * from ULQUEUE END IF But when I write the same query in Oracle, it gives error stating Invalid SQL Statemen

  • Hard drive is not available

    Needing help. My MacBook Pro (late 2010, 13", 250GB/4GB Ram) lost access to mail, then iChat, then address book. Each time I tried to access the mail program or chat, it would crash. Fixed and verified permissions, cleaned out cookies, ran disk utili

  • Error message when trying to sign in

    I enter my apple ID when trying to open iMessage. Moves to the associated email (primary email account) but doesn't accept or do anything past that. I cannot use iMessage at all.

  • Can I turn my old router into a Wireless Acess Point?

    I have recently found my old BEFW11S4 V4 Wireless Router. It has the latest firmware. What I was wondering is it possible to turn it into an Access Point, so that I can increase the range of my Wireless Network. I currently have A wireless router on

  • Sybase ODBC Connection Issue in Windows Server 2008 R2

    Hi , We have three sybase odbc connection in Windows Server 2008 R2 server . One connection is not working now, it was working fine before 30 days. I can ping the server address successfully from BO Server through "dsedit". i have created the same co