Solved Failed if == null statement

Discussion in 'Plugin Development' started by Albkad, Jun 15, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Albkad

    I dont know what I am missing but how is line 3 the problem line?

    Code:
                    if (bblock.getIslands() == null) return;
                    if (bblock.getIslands().getIslandAt(b.getLocation()) == null) return;
                    if (bblock.getIslands().getIslandAt(b.getLocation()).get() == null) return;
                    if (bblock.getIslands().getIslandAt(b.getLocation()).get().getOwner() == null) return;
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Albkad Why do you think that it is a problem line?
     
  3. Offline

    Albkad

    @timtower console says it is

    Caused by: java.util.NoSuchElementException: No value present
    at java.util.Optional.get(Unknown Source) ~[?:1.8.0_202]
    at me.noratgf.quotas.EventListener.onPlantGrow(EventListener.java:57) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_202]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_202]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_202]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_202]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[server.jar:git-Spigot-8043ebc-f690957]
    ... 24 more
    >
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    Albkad

  6. Offline

    timtower Administrator Administrator Moderator

    @Albkad I am asking for the full class to get the line numbers correct.
     
  7. Offline

    Kars

    getLocation.get() is causing the exception. It is not the == null like the title suggests.
    This means the get method is trying to access something that does not exist.
    The fault is in that method.
     
  8. Offline

    Albkad

    @Kars well how do I make sure that there is an island then? because somehow I need to stop the code from reaching the part where I get the uuid of the players island. And if there is no owner then that creates the problem.
     
  9. Offline

    timtower Administrator Administrator Moderator

    @Albkad Do you know how to read javadocs?
    Because the islandAt method returns an optional type, which has an isPresent method.
     
  10. Offline

    Albkad

    I was just about to say nvm I found it. Its easier to ask the question b4 because u take ages to reply. But ye. Thx I guess.
     
  11. Offline

    timtower Administrator Administrator Moderator

    Sorry that we also have other stuff to do.
    Good luck with your plugin.
     
  12. Offline

    Albkad

    @timtower not saying anything about that. Just saying its more practical for me.
     
  13. Offline

    timtower Administrator Administrator Moderator

    That part is confusing to me though.
    You are asking a question. But then you seems to be unhappy about the questions that we ask to get to the actual problem and the speed with which we are doing that.
    They seems kinda going against each other.

    So did you find the solution yourself or not before you responded?
     
  14. Offline

    Albkad

    @timtower Well I feel the question that are asked are kind of unrelevant because they have nothing to do with the problem itself. I feel kind of offended when asked all these questions because it feels like u assume I didnt check anything b4 coming here. And yes I found the solution to the problem afterwards. I asked right after the other guy responded and then I tried looking it up myself and found it. I am just asking the questions b4 just so it saves time for me. Because if I cant find any solution then maybe the people of the community can help. I dont assume ur the only one thats going to respond.
     
  15. Offline

    Kars

    @Albkad You come here and dump your problem on other people. The description you give is vague at best. Not to mention googleable. Then you get offended when you're being asked questions?

    You should be happy you are getting help at all.
     
  16. Offline

    timtower Administrator Administrator Moderator

    @Albkad The questions are asked to get more infornation.
    I do assume that nothing is checked indeed, because it is a good practise to check everything. Including the return type and the javadocs.
     
Thread Status:
Not open for further replies.

Share This Page