Development Assistance NPE

Discussion in 'Plugin Help/Development/Requests' started by BizarrePlatinum, Jun 21, 2015.

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


    I'm getting a NPE here and I'm not quite sure why,

    Stacktrace (open)

    [11:15:49 ERROR]: Error occurred while enabling SimpleSMPHardcore v1.0 (Is it up
     to date?)
            at com.bizarreplatinum.simplesmphardcore.HCListener.<init>(HCListener.ja
    va:25) ~[?:?]
            at com.bizarreplatinum.simplesmphardcore.SimpleSMPHardcore.onEnable(Simp ~[?:?]
            at ~[c
    .java:327) [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.jav
    a:340) [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.
    java:312) [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at net.minecraft.server.v1_8_R1.MinecraftServer.q(
    94) [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at net.minecraft.server.v1_8_R1.MinecraftServer.k(
    62) [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at net.minecraft.server.v1_8_R1.MinecraftServer.a(
    17) [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.jav
    a:190) [craftbukkit-1.8.jar:git-Bukkit-7658819]
    :473) [craftbukkit-1.8.jar:git-Bukkit-7658819]
            at Source) [?:1.7.0_67]

    onEnable (open)

    Bukkit.getServer().getPluginManager().registerEvents(new HCListener(this), this);

    HCListener (open)

    World defaultWorld = Bukkit.getServer().getWorld(plugin.config.getString("hc.default-world"));

    The config does contain the string, and the world does exist.
  2. Offline


    you can do better than that - a bit more code pleae. The problem with "<init>" is a bigger-picture issue with your class and constructors perhaps... I prsume that that was Line 25 for the one error though... which means, need your whole listener class there from declaration / constructor through to that whole registered function, and your declaration/constructor variables and whole on-enable for the main.
    . You most likely arent initializing plugin correctly, or passing the config
  3. Offline


    SimpleSMPHardcore plugin;
        public HCListener(SimpleSMPHardcore instance) {
            plugin = instance;
    I would assume that the problem could be coming from this.
  4. Offline


    not likely - that is a constructor that takes a plugin object argument, and you call a New constructor on it during the onEnable.

    Besides, there is no need for Assumptions when the error message specifies where to start looking
    at com.bizarreplatinum.simplesmphardcore.HCListener.<init>( ~[?:?] -- is it plugin.config?

    If so... is config established in your main class? "Its in my config file" is not the same as "i can read a value from it here".
    Reduce it to steps .. Test if plugin.config.getString("hc.default-world") is null just before you use it.
    Before that one, test if plugin.config is null

    if (plugin.config == null) { Bukkit.getServer().broadcastMessage("AH HA!"); }
  5. Offline



    Thanks for pointing something out that I already knew, why else do you think I would post those line in the op?

    Possibly exactly the thing I posted in the spoiler...

    Yes, config is declared in my main class.

    FileConfiguration config = getConfig();
    I already stated that it is inside my config...

    And i'm pretty sure that unless my plugin doesn't contain a default config that it cannot return null.

    Sorry for my smarta$$edness.
  6. Offline


    I didn't say "make sure that the string is in your config file"
    I said to test if the plugin getting the config string was null there

    But since you're pretty sure, then no point in checking anything.
    The error is all in the head of the server and wishing hard will make it invisible

    To be more precise... if an NPE is thrown on this line:
    World defaultWorld = Bukkit.getServer().getWorld(plugin.config.getString("hc.default-world"));

    These are the things to check for null:
    Bukkit -- no, it will never be null
    Bukkit.getServer() -- also will never be null
    Bukkit.getServer().getWorld(x) -- can be null if world argument is null or invalid string
    .. (plugin.config.getString("x") ) ---
    either plugin can be null but not possible the way you have your class set
    or plugin.config could be null
    or the plugin.config.getString("x") is null

    null argument -> cant get world, assignment fails
    null config -> no object for plugin to get back, argument is null, assignment fails
    plugin.config.getString("x") returns a real object fine as argument, but then getWorld() on it returns a null, and assignment fails..

    Those are the options.
    That is all that can happen in line 25 if a null is there
    No point handwaving and hypothesizing other weird things - SOME OBJECT DEREFERENCES AS NULL right there in that line when used, so identify it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 12, 2016
  7. Offline


    @Boomer Ok, I added the line from your second post and it did not broadcast, so that's not where the problem is coming from. Could it possibly be returning null because the world isn't loaded?
  8. Offline


    broadcast what the plugin.config.getString(x) is to confirm its displaying the world, though it likely is if the config was indeed not null..
    If the world has not been loaded... yes, that would be a problem, since the server hasn't defined an object -placeholder for a world that doesn't 'exist' yet.
  9. Offline


    @Boomer what I meant was say the world file is there, but it is not currently being used, I am in a different world (the plugin was created so worlds could individually be added to hardcore) (not sure if you understood me or not).

    EDIT: It is broadcasting "world" when the line is fired (world is the "default" default world).
  10. Offline


    If the world is loaded by the server during the startup sequence, it should be fine. If your world is NOT loaded by the server, then when your plugin enables, the world is null. Having it ready to load a world in multiverse when-you-want, etc, is not relevent, unless you rearrange how you code your infrastructure to be able to do the meat of the work only after you load the world.
  11. Offline


    @Boomer what could I do to solve this? Anyway I can force the server to keep the world loaded or something? Or just force it to load the world when I need to do something with it?
  12. Offline


    Is the world loaded by the server during startup - yes or no? If no, then yeah, you have some changes to make.
    If it is, then the issue is likely due to there not being any chunks loaded for the world - the server knows the world exists, and will load it into its big-picture knowledge, but only will load the chunks when it needs to.

    If using multiverse, that generally means you can load a world at startup and keep its chunks in memory for spawn... but at the same time, but, that may or may not help yet still if you are trying to teleport to a chunk that isn't loaded..

    There are ways to force the world to load on demand, but, if your plugin is going to require the world object to be made during the onEnable() part of the plugin, then no point in not having it load up thru multiverse at the startup anyways...
    Otherwise, whatever you're doing with that world object during startup, maybe its something you can hold off doing until it is demanded... or even put into a delayed runtime if its an initialization thing, delay it for 200 ticks or so after enabling (10s) to allow everything else to boot up.

    Most importantly, if you need to make sure other non-default worlds are loaded before activating your plugin, add a soft dependancy to multiverse or whatever in your plugin.yml, so that your plugin will load AFTER that has loaded. Cause maybe the issue is that your plugin is loading early, before the world is loaded by multiverse...
Thread Status:
Not open for further replies.

Share This Page