Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • NullPointerException when using getModelColors


    jawa
     Share

    Recommended Posts

    So I'm trying to identify a gameObject by getModelColors().

    GameObject xx = getGameObjects().closest(o -> o.getModelColors()[0] == 2555);

    However, this throws me a nullpointer exception. I've also tried passing it through a filter, no luck.

    Link to comment
    Share on other sites

    35 minutes ago, jawa said:

    So I'm trying to identify a gameObject by getModelColors().

    GameObject xx = getGameObjects().closest(o -> o.getModelColors()[0] == 2555);

    However, this throws me a nullpointer exception. I've also tried passing it through a filter, no luck.

    The gameObject can be null as well as the modelcolors array, you need to null check them beforehand:

    GameObject xx = getGameObjects().closest(o -> o != null && o.getModelColors() != null && o.getModelColors().length > 0 &&  o.getModelColors()[0] == 2555);

     

    Link to comment
    Share on other sites

    Ah silly me... I never checked if the modelColors array was null, only the object itself.

    It works now, thank you once again!

    Link to comment
    Share on other sites

    I found that when setting up the script for mining, it was faster and had better results when searching for the ID numbers of the rocks opposed to the color.  Also had far less trouble with the null pointer exception issue which was happening when trying to check the color of an empty rock.  Just be careful when using ID numbers - I've found that each type of ore has at least two different ID numbers.  It's an easy way to get detected if you're only mining the one ID.

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.