Solved NullPointerExpectation Help

Discussion in 'Plugin Development' started by hellobrad100, Nov 6, 2014.

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

    hellobrad100

    Hello everyone,

    I am trying to make a plugin that will remove Wither Skull Entities when the server is disabled.

    Here is my code:
    Code:java
    1. @Override
    2. public void onDisable()
    3. {
    4. World w = Bukkit.getServer().getWorld(getName());
    5. for(WitherSkull i = (WitherSkull) w.getEntitiesByClass(WitherSkull.class);;)
    6. {
    7. i.remove();
    8. }
    9. }


    However, I seem to be getting a NullPointerExpectation, either I'm missing something obvious or just being dumb, I don't know.

    Could you help me by pointing me in the right direction?

    Code:
    [21:28:21] [Server thread/INFO]: [WitherSkull] Disabling WitherSkull v1
    [21:28:21] [Server thread/ERROR]: Error occurred while disabling WitherSkull v1 (Is it up to date?)
    java.lang.NullPointerException
        at com.brad.Wither.Main.onDisable(Main.java:20) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:318) ~[craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:356) [craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:436) [craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:429) [craftbukkit.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.disablePlugins(CraftServer.java:412) [craftbukkit.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.stop(MinecraftServer.java:393) [craftbukkit.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:525) [craftbukkit.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Spigot-1649]
    Thanks, Brad
     
  2. Offline

    WesJD

    hellobrad100
    What is this madness?
    Code:java
    1. for(WitherSkull i = (WitherSkull) w.getEntitiesByClass(WitherSkull.class);;)
     
  3. Offline

    TheCodingCat

    here is what you should do hellobrad100
    Code:java
    1. // on disable
    2. for (Entity e : <world>.getEntities()) {
    3. if (e.getType().equals(EntityType.WITHER_SKULL)) {
    4. e.remove();
    5. }
    6. }
     
  4. Offline

    _Filip

    TheCodingCat Don't check enum values using .equals when you can do ==.
     
  5. Offline

    hellobrad100

    TheCodingCat
    I used your method in 2 ways and it still comes up with the error.
    Used both .equals and ==

    Any other ideas? :p
     
  6. Offline

    WesJD

  7. Offline

    hellobrad100

    Sorted.

    I was just being really... really stupid..
     
Thread Status:
Not open for further replies.

Share This Page