1.15.2 unrecognized problem(again)

Discussion in 'Spigot Plugin Development' started by Phoenix852, Feb 12, 2020.

  1. I now have a problem with the PlayerBedEnterEvent.

    Here is what I get from the console
    And this is my code
    Code (Java):
        public void onBedEnter(PlayerBedEnterEvent e) {
            Player p = e.getPlayer();
            String bedentermsg = getConfig().getString("bedentermsg");
            String bedentermsg1 = bedentermsg.replaceAll("%PLAYER%", p.getName());
            p.sendMessage(bedentermsg1);
        }
    Everything else is ok,, just help me fix this shit.
     
  2. You need to learn how to read stack traces, this line:

    Code (Text):
    java.lang.NullPointerException: null
    at com.thunderkofy.ironxmessages.onBedEnter(ironxmessages.java:63) ~[?:?]
    Says that something on line 63 is null, so which line is 63?

    I'm guessing it's
    Code (Text):
    getConfig().getString("bedentermsg")
    ...?
     
  3. SteelPhoenix

    Moderator

    Also, unless you're working with regular expressions you don't need to use #replaceAll(...)
     
  4. line 63 is
    Code (Text):
    String bedentermsg1 = bedentermsg.replaceAll("%PLAYER%", p.getName());
    I don't see anything to be null here...
     
    • Creative Creative x 1
  5. bedentermsg can still be null. There is no verification that the config isn’t returning null when you use getString(). Maybe check for null before or use getString() with a default value.
     
  6. I think "bedentermsg" is null, can you print it out just before line 63 through Bukkit.broadcastMessage or something like that to check?
     
    • Like Like x 1
  7. Yea it was returning to null but after I did a System.out.println(bedentermsg);
    It is not returning null, but I don't want to do that obviously. What to do?
     
  8. the config isnt finding the value necessary. check the config.yml on the server and see if the key youre attempting to fetch is there. if its not, theres your problem. if it is, you may just need to reload the config
     
  9. I checked the config.yml, but everything seems to be right. I dunno what is wrong with this.
     
  10. Can you show us your config?
     
    • Like Like x 1
  11. Sure but I made bit more changes to the plugin. I am gonna dm you the source code and the config.yml and please help me. Thank you.
     
  12. Its a problem with solutions written again and again,dont think this is worth going into dms or keeping it a secret at this point
     
    • Friendly Friendly x 1