NullPointerException - but why?

I have a line of code throwing a NullPointerException:
nearestPrey = preyCreature[0];Now, I know that the Prey object in preyCreature[0] exists because it's a Thread and is running already by this point! I've tried using index 1 to check for a slip up when instantiating, but it's not that.
Any ideas?
Cheers,
Charles

The array gets initilised in this bit of code:
    Prey[] preyCreature = new Prey[maxPrey];..
    for (int i = 0; i < noOfPrey; i++){
      preyCreature[i] = new Prey(i, env, initLocation, preyChange, gordon);
    preyCreature.initPrey(noOfGenerations, f, gridWidth,
gridHeight, preyCreature, noOfPrey, maxPrey, preyGroupSize,
noOfPredTeams, predtm, maxPreySpeed, preyAcceleration,
preyDeceleration, easeOfPreyTurning, preySightRange, birthChance);
System.out.println("Starting prey...");
for (int i = 0; i < noOfPrey; i++)
preyCreature[i].start();
The line of code mentioned in my first post is in this method:
  public void findNearestPrey()
    preyChange.P(); // avoid prey being killed while searching for it
    nearestPreyDead = false;
    nearestPrey = preyCreature[0];
    preyDistance = f.distanceTo(predX, predY,
     preyCreature[0].getX(), preyCreature[0].getY());
    preySpeed = preyCreature[0].getSpeed();
    preyEnergy = preyCreature[0].getEnergy();
    angleToPrey = f.angleTo(predX, predY, preyCreature[0].getX(),
    preyCreature[0].getY(), predDir);
    for (int i = 1; i < noOfPrey; i++)
      if (f.distanceTo(predX, predY, preyCreature.getX(),
preyCreature[i].getY()) < preyDistance) {
nearestPrey = preyCreature[i];
preyDistance = f.distanceTo(predX, predY,
preyCreature[i].getX(), preyCreature[i].getY());
preySpeed = preyCreature[i].getSpeed();
preyEnergy = preyCreature[i].getEnergy();
angleToPrey = f.angleTo(predX, predY, preyCreature[i].getX(),
preyCreature[i].getY(), predDir);
preyChange.V();
This method is in a different object that is also a Thread (started immediately after the Prey Threads). Do you need anything else?
Charles

Similar Messages

  • How can i fix my iphone i can't update or download apps, when i try it tells me toput my credit card info and i do but when i push done it tells me my payment has been declined, but why do i have to pay to update or download free apps. How can i fix this?

    how can i fix my iphone i can't update or download apps, when i try it tells me toput my credit card info and i do but when i push done it tells me my payment has been declined, but why do i have to pay to update or download free apps. How can i fix this?

    You must contact iTunes support to get the problem resolved.
    http://www.apple.com/support/itunes/contact/
    If there is a problem with your account or payment info, you cannot
    download anything (including free apps or updates) until the matter
    is resolved.
    In countries where the iTunes Store only sells apps, the accepted payment methods are Visa, MasterCard, and American Express. Other payment types such as gift cards, store credit, monthly allowances, ClickandBuy, and PayPal are not accepted. Depending on your App Store country, prices may be listed in your local currency, US Dollars, or Euros.    http://support.apple.com/kb/HT5552

  • My ipod touch is stuck on the apple logo and after a while a white screen comes up and it restarts and the same thing all over agan. this happened to me before and after a while it turns on but why does it keep on doing this?

    my ipod touch is stuck on the apple logo and after a while a white screen comes up and it restarts and the same thing all over agan. this happened to me before and after a while it turns on but why does it keep on doing this?

    Try connecting the iPod Touch to your computer and restore it.  http://support.apple.com/kb/HT1414

  • Keynote and pages are now free, but why do i need to pay for them still when there now free?!?

    keynote and pages are now free, but why do i need to pay for them still when there now free?!?

    Users can obtain the iWorks and iLife applications free, if they purchased a Mac after the beginning of October 2013.
    Older Mac purchases require a paid purchase of these applications.

  • I am from Bangladesh. I can't log in with my gmail Apple ID. When I put in the mail and password, and press sign in, it says it has to review on iTunes. Then I am directed to opening a new account. But why should I , since I have one. Plz help :(

    I am from Bangladesh. I can't log in with my gmail Apple ID. When I put in the mail and password, and press sign in, it says it has to review on iTunes. Then I am directed to opening a new account. But why should I , since I have one. Plz help

    Hi Ishrak,
    I apologize, I'm a bit unclear on exactly what you are trying to log into with your Apple ID, or what exactly you are seeing (alert message, directions, etc) when you try to do so. If you continue to have issues with your Apple ID, you may find one or more of the articles linked from the following page helpful:
    Apple ID - Apple Support
    Regards,
    - Brenden

  • I just brought Macbook pro(without retina display) on 15 june 2013 and since then put it on 6-7 hours of charging but still my macbook pro is not 100% charged. but why? (green light is displayed on the adapter pin)

    i just brought Macbook pro(without retina display) on 15 june 2013 and when i switched it on the battery was 72 % charged and now the battery is charged to 62%, i used the charger that came with it and kept it for 6-7 hours on charging but it is not charged to 100% but why? also the green light is always on when i plug the charger with my mac book pro.Please tell me the meaning of Green light on power cord lid (mac book pro not charging or charging?) and also the other light if there like amber or any other colour.

    Hello Shailendras33,
    Congratulations on your new MacBook Pro!  Thank you for providing all the information about what is going on with the charging issue. 
    Firstly, I found some information on page 11 of the MacBook Pro User Guide about what each color of the LED means on the Power Adapter:
    When you first connect your power adapter to your MacBook Pro, an indicator light on the
    MagSafe connector starts to glow.  An amber light indicates the battery is charging.  A green light indicates that the battery is fully charged.
    You can find the MacBook Pro User Guide here (this is not for the latest MacBook Pro, but the information about the MagSafe adapter is true for the newest model):
    MacBook Pro User Guide
    http://manuals.info.apple.com/en_US/macbook_pro_15inch_late_2011.pdf
    It sounds like you are not getting the amber light indicating your computer is charging, and you are noticing that the battery level is depleting.  I recommend resetting your System Management Controller when something like this is occurring:
    Resetting the SMC on portables with a battery you should not remove on your own
    Note: Portable computers that have a battery you should not remove on your own include MacBook Pro (Early 2009) and later, all models of MacBook Air, and MacBook (Late 2009).
    Shut down the computer.
    Plug in the MagSafe power adapter to a power source, connecting it to the Mac if its not already connected.
    On the built-in keyboard, press the (left side) Shift-Control-Option keys and the power button at the same time.
    Release all the keys and the power button at the same time.
    Press the power button to turn on the computer. 
    Note: The LED on the MagSafe power adapter may change states or temporarily turn off when you reset the SMC.
    You can find the full article here:
    Intel-based Macs: Resetting the System Management Controller (SMC)
    http://support.apple.com/kb/ht3964
    Thank you for posting in the Apple Support Communities. 
    Best,
    Sheila M.

  • I can no longer down load on iTunes said I need a new payment method but why does my bank card no longer work how do I fix this

    Hey everyone I can no longer down load or up date my games videos so on on iTunes
    It's telling me I need a new payment method  but why would my bank card no longer work how can I fix it so my bank card works again

    how do i fix this

  • HT201272 I can see my previously purchase music, it says downloaded but why can't i download the music? The were accidentally deleted from the itune folder?

    I can see my previously purchase music, it says downloaded but why can't i download the music? The were accidentally deleted from the itune folder?

    Do I have to have icloud to download previously purchased music?

  • Full screen is great but why take out my links bar?

    Full screen is great but why take out my links bar?
    Is there an option or customisation to show it in full screen mode..  I can understand taking out the file menu but that second delay is unpreciated to access links also.

    Hi Atomic AI
    can I achieve the opposite - I would like to start my full screen safari without the title bar, links bar or similar. just nothing except the content of the page - is this possible? I cant figure it out

  • Goodnight gracie, I know this is trivial but why?

    I know this is trivial but in System profiler in the syncservices log i find this, or variantys thereof:
    2011-06-13 20:45:44:432|SyncServer|1994|110fd0|Server|Info| Goodnight, Gracie.
    I think it a message  when the mac goes into sleep mode. But why 'Goodnight Gracie' Apparently it was a catchprase used by George Burns at the end of his radio show, but does anyone know who or why it was included in this log message?
    mike

    Someone may, but it was put in there by one of the programmers as a joke.

  • "ORA-1715 : UNIQUE may not be used with a cluster index" but why?

    "ORA-1715 : UNIQUE may not be used with a cluster index" but why and what "may" means here? Any comments will be welcomed, thank you and best regards;
    show rel
    release 1002000300
    CREATE CLUSTER sc_srvr_id (
    srvr_id NUMBER(10)) SIZE 1024;
    SELECT cluster_name, tablespace_name, hashkeys,
    degree, single_table FROM user_clusters;
    CREATE UNIQUE INDEX idx_sc_srvr_id ON CLUSTER sc_srvr_id;
    ERROR at line 1:
    ORA-01715: UNIQUE may not be used with a cluster index
    CREATE INDEX idx_sc_srvr_id ON CLUSTER sc_srvr_id;
    SELECT index_name, index_type, tablespace_name
    FROM user_indexes where index_name like '%SRVR%' ;
    CREATE TABLE cservers (
    srvr_id    NUMBER(10),
    network_id NUMBER(10),
    status     VARCHAR2(1),
    latitude   FLOAT(20),
    longitude  FLOAT(20),
    netaddress VARCHAR2(15))
    CLUSTER sc_srvr_id (srvr_id);
    ALTER TABLE cservers add constraint pk_srvr_id primary key (srvr_id ) ;
    SELECT index_name, index_type, tablespace_name
    FROM user_indexes where index_name like '%SRVR%' ;
    INDEX_NAME                     INDEX_TYPE
    TABLESPACE_NAME
    IDX_SC_SRVR_ID                 CLUSTER
    USERS
    PK_SRVR_ID                     NORMAL
    USERSdo we really need another pkey index here?

    "May" has different meanings, one of which is:
    (used to express opportunity or permission)
    Metalink note 19067.1 says:
    This is not permitted.
    ... which agrees with the above meaning of it.
    Besides these, it does not make any sense to me to create a unique index on a cluster. You can have primary keys in the tables you include in the cluster, it depends on your business requirement. But why do you need a unique index on a cluster?

  • In Siri, I can call by my voice, but why I can not use Siri voice call in my country (Laos), just can call only us phone number; my country we use like 3 number for option call, 8 numbers for call friend but Siri cannot use this please help us, thanks

    In Siri, I can call by my voice, but why I can not use Siri voice call in my country (Laos), just can call only us phone number; my country we use like 3 number for option call, 8 numbers for call friend but Siri cannot use this please help us, thanks
    And please help me can type Laos font in it like andrio phone.

    Hi Cozumel,
    Thanks for posting. I'm sorry you're having problems with your bills. I can take a look at this for you. Drop me an email with your account details and a link to this thread for reference. You'll find the address in my profile.
    Cheers
    David
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)

  • HT3702 apps store said that the game is free but why the bill says it need money?  please reply me!!!!!

    apps store said that the game is free but why the bill says it needs money?
    please reply me soon!!!!
    chan family
    <Email Edited By Host>

    Did you add or change your credit card details when downloading the app ? If so then you've probably received a temporary store holding charge, which should disappear within a few days : holding charges. Or have you made any in-app purchases within the app (what app is it) ? If you log into your account on your computer's iTunes (Store > View My Account), what shows under your purchase history ?
    As these are user-to-user forums, you are not talking to Apple here, I've asked the hosts to remove your email address from the post's title.

  • Transport shows successfull but why it is not taking effect in test

    Hi all ,
    I have changed my dataource and added some Z fields .
    But when i transport that to test system, i can not see the effect in test .
    Transport shows successfull but why it is not takin effect from the Dev Datasource changes to Test systems ?
    Please give me solution

    Hi,
    You can check the version of the data source.
    Check this version if shows the latest date and the TR number on which you have transported the data source.If it contains different one then select your one and activate it.
    You can actually activate the desired version.
    Just go RSO2->Extract structure->utiliteis-> version -> version management.
    Thanks

  • Looking forward to download Adobe After Effects CC from Creative Cloud Desktop Application. But why most of the apps appear to be in CS6?

    I installed the new copy of Adobe Creative Cloud Desktop Application, and looking forward to download Adobe After Effects CC. But why most of the apps appear to be in CS6? - Including AE. Only few appears to be CC.
    Thank you.

    A chat session where an agent may remotely look inside your computer may help
    Creative Cloud chat support (all Creative Cloud customer service issues)
    http://helpx.adobe.com/x-productkb/global/service-ccm.html

Maybe you are looking for