Getting a NPE

Discussion in 'Plugin Development' started by JordyPwner, Aug 23, 2014.

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

    JordyPwner

    Im getting a NPE at my cooldown class on line 21:

    Line 21: plugin.cooldown1.put(player.getName(), plugin.cooldown1.get(player.getName()) - 1);

    Does anyone know why?
     
  2. Offline

    teej107

    • plugin is null
    • OR
    • cooldown1 is null
    • OR
    • player is null
     
  3. Offline

    JordyPwner

  4. Offline

    Yekllurt

    Is your player in the HashMap?
     
  5. Offline

    JordyPwner

    Yekllurt teej107 new error:


    Show Spoiler
    ... 15 more
    [20:04:15 ERROR]: Could not pass event PlayerInteractEvent to FunCannon v1.0.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:225) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-
    g07d4558-b3116jnks]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:195) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-
    g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :606) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.a(SourceFile:60)
    [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.handle(SourceFile
    :9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157
    ) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:6
    67) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    58) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    58) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.NullPointerException
    at me.jordypwner.FunCannon.FunCannon3.onPlayerInteract(FunCannon3.java:3
    1) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_60]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_60]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    ... 15 more


    line 31: if (plugin.cooldown1.get(p.getName()) <= 0) {
     
  6. Offline

    teej107

    It's simple. Make sure you assign your variables to values.
     
  7. Offline

    JordyPwner

  8. Offline

    teej107

  9. Offline

    reider45

    Make sure that cooldown1 actually contains the player.
     
  10. Offline

    JordyPwner

    reider45 how :p im a beginning at developing so im still a noob :p
     
  11. Offline

    bennie3211

    don't bump your thread within 24 hours And no one will spoon-feed you, so first learn some java before you start working with the bukkit api :)
     
  12. Offline

    JordyPwner

    bennie3211 people learn from the good answer not a idiot that things he is a pro developer -_-
     
  13. Offline

    reider45


    Code:java
    1. if(cooldown1.contains(p.getName()){
    2.  
    3. }
     
    JordyPwner likes this.
  14. Offline

    JordyPwner

    reider45 where do i place this? sorry i forgot it :p
     
  15. Offline

    indyetoile

    JordyPwner
    Don't give such an arrogant attitude to people who are telling you the truth.

    The questions you're asking prove that you don't have any basic Java knowledge, and no, you didn't 'forget' where to put it, you don't have any idea.
     
    bennie3211 likes this.
  16. Offline

    JordyPwner

    • Please control your temper. Outbursts such as this are not appropriate forum behavior.
    indyetoile i have a idea but i forgot where to place it so please stfu if you post useless comments
     
  17. Offline

    SmooshCakez

    If you want to check whether a player is in the cooldown1 HashMap before doing that, put it around where you get the values from the HashMap. (line 21) Also, it's best learn Java and then do it if you don't understand what your doing.
     
    indyetoile likes this.
  18. Offline

    reider45

    Can you post your class?
     
  19. Offline

    bennie3211

    I agree with this :) If you learn Java first, you can program things yourself, and you don't have to ask the 'basic' things anymore. ;)



    I'm not a pro developer nor a Idiot, I need help too, but I'm just telling you the truth. And you won't learn from a "good answer" because 100% of the "spoon-feed" will be copy-pasted into your class xD. You asked for a full spoon-feeded class, and I think a lot of the people here won't help people that ask for it.


    How can you forget this?! If you don't know where to place that piece of code, you can better redo the basics. And be a little bit more polite... people try to help you and saying "stfu" for telling you to learn the basics of Java first, isn't nice at all. If you talk like that, no one is going to help you with the problems that you're facing.

    I just want to tell you that being polite will help you more. A second tip I will give you is go learn the basics first. If you can't handle the basic Java knowledge, you won't know how to use the Bukkit API either.

    Maybe this will help you ;)
    - Stack-trace debug: http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/
    - Java basics (Here you can find a lot of useful things): http://docs.oracle.com/javase/tutorial/java/nutsandbolts/
    - Java docs: http://docs.oracle.com/javase/7/docs/api/

    [EDIT]

    Still not convinced? Check this: http://forums.bukkit.org/threads/java-then-bukkit-api.306934/
     
    indyetoile and keelar like this.
Thread Status:
Not open for further replies.

Share This Page