java NullPointerException

Discussion in 'Plugin Development' started by deleted_91027365, Feb 26, 2015.

Thread Status:
Not open for further replies.
  1. Hey,

    I cant fix this bug...

    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            boolean joinenable = getConfig().getBoolean("Config.joinmsg_enabled", false);
            String joinmsg_bc = getConfig().getString("Config.joinmsg");
            joinmsg_bc = joinmsg_bc.replace("[Playername]", e.getPlayer().getName());
            if(joinenable == true); {
            e.setJoinMessage(joinmsg_bc);
            }
        }
    Config:

    Code:
    Config:
      space_motd: 'There is space for you!'
      full_motd: 'Sorry, were full :('
      freewhen: '19'
      joinenable: 'true'
     
      joinmsg_bc: '%Playername% joined the Server'
     
    

    So, if a Player joins the server, the Minecraft means "No Reaction"... After a while you joined the Server but theres a error!

    Code:
    Could not pass evnet PlayerJoinEvent to SmoothMOTD
    .
    .
    .
    Caused by: java.lang.NullPointerException
    .
    .
    .
    
     
  2. Offline

    greyhunter99

    In your configfile there is a value called joinmsg_bc. And you try to get that in your onJoin() with the
    getConfig().getString("Config.joinmsg");
    which should be
    getConfig().getString("Config.joinmsg_bc");
     
  3. Offline

    mine-care

    @dunklesToast its a good idea to provide the whole stacktrace. not just the poimt where it mentions the NPE

    Dont compare boolean values in if's there is no need. simply use:
    if(joinenable){} and to check for false: if(!joinenable){}

    you havent specified the right path for the string.
    Also an efficiency tip. dont make server open config, and getting info every time someone joins, simply keep those variables stored in ram by initialising them onEnable(). Its a common mistake.
     
  4. OKAY! Maybe its better with the onEnable thing :D

    @mine-care If I put the config things into the onEnbale, the Problem is, that clipse dont accept them...
    If i change it to i.ex. Main.full_motd same error too

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Feb 26, 2015
  5. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page