Null pointer in delayed task.

Discussion in 'Plugin Development' started by Amazing_kid, Nov 6, 2013.

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

    Amazing_kid

    Heres my code:
    Code:java
    1. int errors = 0;
    2. for (Block b : blocks.keySet()){
    3. if (b.getType() != Material.AIR){
    4. errors++;
    5. }
    6. }
    7. if (errors < 10){
    8. for (Map.Entry<Block, Material> entry : blocks.entrySet()){
    9. Block b = entry.getKey();
    10. Material m = entry.getValue();
    11. b.setType(m);
    12. }
    13. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    14. public void run(){
    15. for (Block b : blocks.keySet()){
    16. b.setType(Material.AIR);
    17. }
    18. }
    19. }, 20 * 15);
    20. } else {
    21. p.sendMessage("You cannot place a safehouse here! " + errors);
    22. }


    I am getting the following errors when it is suppose to change the building back into air.

    Code:
    [SIZE=10px][FONT=Monaco][COLOR=#f5f5f5]20:30:35 [WARNING] [test] Task #27 for test v0.1 generated an exception[/COLOR][/FONT][/SIZE]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]java.lang.NullPointerException[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at net.minecraft.server.v1_6_R3.Chunk.a(Chunk.java:383)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at net.minecraft.server.v1_6_R3.World.setTypeIdAndData(World.java:301)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at org.bukkit.craftbukkit.v1_6_R3.block.CraftBlock.setTypeId(CraftBlock.java:108)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at org.bukkit.craftbukkit.v1_6_R3.block.CraftBlock.setType(CraftBlock.java:104)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at com.github.epicshadow.test.SafeHouse$1.run(SafeHouse.java:374)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:53)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:524)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)[/SIZE][/FONT][/COLOR]
    [COLOR=#f5f5f5][FONT=Monaco][SIZE=10px]at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)[/SIZE][/FONT][/COLOR]
    
    Any ideas why/possible solutions? Thanks
     
  2. Offline

    Jake0oo0

    Notice:
    at com.github.epicshadow.test.SafeHouse$1.run(SafeHouse.java:374)

    Whats line 374?
     
  3. Offline

    Amazing_kid

    Jake0oo0
    Its this line
    Code:java
    1. b.setType(Material.AIR);
     
  4. Offline

    Jake0oo0

    Amazing_kid Make sure the block, etc, isn't null, add a bit of debug to see if there's any issues.
     
  5. Offline

    Vexil

    Try this:
    Code:java
    1. if(!b.getType().equals(Material.AIR)) {
    2.  
    3. b.setType(Material.AIR);
    4.  
    5. }
     
  6. Offline

    Amazing_kid

    Ok Thanks ill give it a try and let you know the result.

    Jake0oo0 BenCS_

    Just got this error:
    Code:
    21:53:30 [WARNING] Failed to handle packet for Nebula111/127.0.0.1: net.minecraft.server.v1_6_R3.ReportedException: Colliding entity with tile
    net.minecraft.server.v1_6_R3.ReportedException: Colliding entity with tile
        at net.minecraft.server.v1_6_R3.EntityPlayer.h(EntityPlayer.java:282)
        at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:343)
        at net.minecraft.server.v1_6_R3.Packet10Flying.handle(SourceFile:136)
        at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
        at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
        at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
        at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.NullPointerException
        at net.minecraft.server.v1_6_R3.Entity.D(Entity.java:734)
        at net.minecraft.server.v1_6_R3.Entity.move(Entity.java:677)
        at net.minecraft.server.v1_6_R3.EntityLiving.e(EntityLiving.java:1188)
        at net.minecraft.server.v1_6_R3.EntityHuman.e(EntityHuman.java:1229)
        at net.minecraft.server.v1_6_R3.EntityLiving.c(EntityLiving.java:1444)
        at net.minecraft.server.v1_6_R3.EntityHuman.c(EntityHuman.java:371)
        at net.minecraft.server.v1_6_R3.EntityLiving.l_(EntityLiving.java:1277)
        at net.minecraft.server.v1_6_R3.EntityHuman.l_(EntityHuman.java:157)
        at net.minecraft.server.v1_6_R3.EntityPlayer.h(EntityPlayer.java:228)
        ... 11 more
    The client also said "Internal Error"

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

    Jake0oo0

    Is this having to do with portals? After a bit of googling thats what seems to come up.
     
  8. Offline

    Amazing_kid

    Jake0oo0 What? It has nothing to do with portals. All it does is go through a hash map with blocks and materials and set the blocks to air.
     
  9. Offline

    Amazing_kid

Thread Status:
Not open for further replies.

Share This Page