buildTo(Locatable a).step() will throw an NPE sometimes

Discussion in 'Developer Support' started by Dibes, Jun 24, 2015.

  1. When I run this code it sometimes throws an NPE and I can't figure out why

    Code (Text):
    1.  GameObject obelisk = GameObjects.newQuery().names("Small obelisk").results().first();
    2.         if (obelisk != null && !obelisk.isVisible()) {
    3.             Traversal.getDefaultWeb().getPathBuilder().buildTo(obelisk.getPosition()).step();
    4.             Camera.passivelyTurnTo(obelisk);
    5.         }
     
  2. You're not null checking your path. If a path can't be generated it'll return null.
     
  3. Ah thanks! I didn't know that :)
     

Share This Page

Loading...