Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointer at getId #1

Open
SandroCoutinho opened this issue Aug 27, 2017 · 6 comments
Open

NullPointer at getId #1

SandroCoutinho opened this issue Aug 27, 2017 · 6 comments
Assignees
Labels

Comments

@SandroCoutinho
Copy link
Member

SandroCoutinho commented Aug 27, 2017

java.lang.NullPointerException
    at org.rev317.min.api.wrappers.NpcDef.getId(NpcDef.java:42)
    at org.rev317.min.api.wrappers.NpcDef.getId(NpcDef.java:21)
    at org.emmastone.parabot.scripts.dreamscape.shadowking.strategies.Attack.lambda$activate$0(Attack.java:16)
    at org.rev317.min.api.methods.Npcs.getNpcs(Npcs.java:54)
    at org.rev317.min.api.methods.Npcs.getNearest(Npcs.java:111)
    at org.emmastone.parabot.scripts.dreamscape.shadowking.strategies.Attack.activate(Attack.java:16)
    at org.parabot.environment.scripts.framework.StrategyWorker.execute(Frameworks.java:55)
    at org.parabot.environment.scripts.Script.run(Script.java:113)
    at java.lang.Thread.run(Thread.java:748)
@JKetelaar
Copy link
Member

Could you provide the code you're using to reproduce this error?

@SandroCoutinho
Copy link
Member Author

SandroCoutinho commented Aug 27, 2017

import org.rev317.min.api.methods.Npcs;

public class Attack implements org.parabot.environment.scripts.framework.Strategy {

    @Override
    public boolean activate() {
        Npcs.getNearest(npc -> npc.getDef().getId() == Constants.SHADOWKING_ID)

        return false;
    }

    @Override
    public void execute() { }
}

@JKetelaar
Copy link
Member

FYI: Updated your code to only provide code regarding the error.

@JKetelaar
Copy link
Member

What is the desc value of the id field of NpcDef in the client?

@JKetelaar JKetelaar self-assigned this Aug 29, 2017
@JKetelaar JKetelaar added the bug label Aug 29, 2017
@SandroCoutinho
Copy link
Member Author

SandroCoutinho commented Aug 29, 2017

long

@SandroCoutinho
Copy link
Member Author

SandroCoutinho commented Jul 16, 2018

A way to fix this issue is to surround Npc.getNearest with a try/catch
Example

            try {
                Npc[] npcs = Npcs.getNearest(new Filter<Npc>() {
                    @Override
                    public boolean accept(Npc npc) {
                        return npc.getDef().getId() == Constants.AUBURY_ID;
                    }
                });
            } catch (NullPointerException ignored) {
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants