Solved Why would this be null

Discussion in 'Plugin Development' started by KoalaOnCaffeine, Sep 14, 2018.

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

    KoalaOnCaffeine

    Hi! I was creating a prison plugin when I found this error when I interact with blocks:
    Code:
     Could not pass event PlayerInteractEvent to Prison v1.0
    org.bukkit.event.EventException: null
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[Server.jar:git-Spigot-eb3d921-2b93d83]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Server.jar:git-Spigot-eb3d921-2b93d83]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:235) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:202) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.PlayerInteractManager.a(PlayerInteractManager.java:109) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:875) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockDig.a(SourceFile:40) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockDig.a(SourceFile:10) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [Server.jar:git-Spigot-eb3d921-2b93d83]
            at java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.NullPointerException
            at me.koalaoncaffeine.prison.InteractEvent.onClick(InteractEvent.java:25) ~[?:?]
            at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
            at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[Server.jar:git-Spigot-eb3d921-2b93d83]
            ... 18 more
    And im just curious about WHAT exactly is making this null,
    upload_2018-9-14_19-58-5.png
    (My 2 classes that are causing the error)

    Thanks for your help <3
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    KoalaOnCaffeine

    What do you mean? I dont have to initialize that class, Im not using it for anything except an event, which is registered in my Main class.
     
  4. Online

    timtower Administrator Administrator Moderator

    Then please show that line.
     
  5. Offline

    KoalaOnCaffeine

    upload_2018-9-14_20-3-40.png @timtower
    I have a seperate constructor so i dont need to mess with extra args btw
     
  6. Online

    timtower Administrator Administrator Moderator

    @KoalaOnCaffeine Yeah, that constructor is the issue.
    You are using c, but you never initialize it.
     
  7. Offline

    KoalaOnCaffeine

    private CreateMineCommand c;

    public InteractEvent(CreateMineCommand c) {
    this.c = c;
    }

    Should work though right?
     
  8. Online

    timtower Administrator Administrator Moderator

  9. Offline

    KoalaOnCaffeine

    Ahh ok!
    EDIT:
    @timtower Now my event just isnt working at all??? (in regrads to the hashmap called inChoose)
     
  10. Try making it a static HashMap, removing all constructors and using:


    Code:
    mapClass.mapName.whateverNeedsDoing
    
     
  11. Online

    timtower Administrator Administrator Moderator

    @KoalaOnCaffeine Then please post your new code.

    And how would that solve everything besides the fact that you never need static within Bukkit? (or java at all in that regard)
     
    KoalaOnCaffeine likes this.
  12. Actually coming to think of it, that's a good point. Dunno why I suggested it in the first place
     
Thread Status:
Not open for further replies.

Share This Page