NullPointerException

Discussion in 'Plugin Development' started by FlareLine, Apr 6, 2014.

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

    FlareLine

    I'm currently making a plugin, but I've come across an NPE:
    Show Spoiler
    Code:
    [12:46:15 WARN]: java.lang.NullPointerException
    [12:46:15 WARN]:        at me.genki.ms.JoinGui.onPlayerJoin(JoinGui.java:28)
    [12:46:15 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
    ethod)
    [12:46:15 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
    ource)
    [12:46:15 WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
    wn Source)
    [12:46:15 WARN]:        at java.lang.reflect.Method.invoke(Unknown Source)
    [12:46:15 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(Jav
    aPluginLoader.java:292)
    [12:46:15 WARN]:        at org.bukkit.plugin.RegisteredListener.callEvent(Regist
    eredListener.java:62)
    [12:46:15 WARN]:        at org.bukkit.plugin.SimplePluginManager.fireEvent(Simpl
    ePluginManager.java:501)
    [12:46:15 WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(Simpl
    ePluginManager.java:486)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.PlayerList.c(PlayerList.
    java:229)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.PlayerList.a(PlayerList.
    java:116)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.LoginListener.c(LoginLis
    tener.java:78)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.LoginListener.a(LoginLis
    tener.java:42)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.NetworkManager.a(Network
    Manager.java:150)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.ServerConnection.c(Sourc
    eFile:134)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.MinecraftServer.v(Minecr
    aftServer.java:657)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.DedicatedServer.v(Dedica
    tedServer.java:250)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.MinecraftServer.u(Minecr
    aftServer.java:548)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.MinecraftServer.run(Mine
    craftServer.java:459)
    [12:46:15 WARN]:        at net.minecraft.server.v1_7_R2.ThreadServerApplication.
    run(SourceFile:618)


    JoinGui Method:
    Code:java
    1. try{
    2. for(int x = 1 ; x > 0; x++) {
    3.  
    4. if(ms.c1(x) == null){ // <-- Line 28
    5. ms.c2("p." + x, pu);
    6. p.sendMessage("Added");
    7. break;
    8. } else {
    9. continue;
    10. }
    11. }
    12. } catch (Exception e) {
    13. e.printStackTrace();
    14. }


    Main Class:
    Code:java
    1. public String c1(int x){
    2.  
    3. String s = config.getString("p." + x);
    4. return s;
    5.  
    6. }
    7.  
    8. public void c2(String s, String a){
    9. config.set(s, a);
    10. }

    I'm not sure what I am doing wrong...
     
  2. Offline

    TeeePeee

    "ms" is null. Also, your for loop is infinite (some number is one, as long as some number is greater than 0, increment some number). Well, I suppose it will terminate when the int overflows to Integer.MIN_VALUE. But that's no way to do loop.
     
  3. Offline

    FlareLine

    TeeePeee It will not infinitely loop as the loop breaks if it gets to a point. Anyway this is fixed.
     
  4. Offline

    TeeePeee

    FlareLine
    Oops, never saw the break on my glance. Just read the for parameters and line 28. Sorry!
     
Thread Status:
Not open for further replies.

Share This Page