Random function didin't work...

Discussion in 'Plugin Development' started by Tomass, Sep 27, 2013.

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

    Tomass

    SOLVED!
    Why I get error when I try to join to the server. I use Random rnd variable. Why It's didn't work?
    Code:java
    1. public void onJoining(PlayerJoinEvent e)
    2. {
    3. byte c = (byte) rnd.nextInt(3);
    4. byte team = (byte) rnd2.nextInt(2);

    In console I get this:
    Code:java
    1. [SEVERE] Could not pass event PlayerJoinEvent to myplugin v0.3
    2.  
    3. org.bukkit.event.EventException
    4.  
    5. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    6.  
    7. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    8.  
    9. at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
    10.  
    11. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:478)
    12.  
    13. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:463)
    14.  
    15. at net.minecraft.server.v1_6_R2.PlayerList.c(PlayerList.java:208)
    16.  
    17. at net.minecraft.server.v1_6_R2.PlayerList.a(PlayerList.java:104)
    18.  
    19. at net.minecraft.server.v1_6_R2.PendingConnection.e(PendingConnection.java:135)
    20.  
    21. at net.minecraft.server.v1_6_R2.PendingConnection.d(PendingConnection.java:48)
    22.  
    23. at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:132)
    24.  
    25. at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:592)
    26.  
    27. at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:239)
    28.  
    29. at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:481)
    30.  
    31. at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:413)
    32.  
    33. at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    34.  
    35. Caused by: java.lang.NullPointerException
    36.  
    37. at com.gmail.godplaylt.myplugin.Main.onJoining(Main.java:94)
    38.  
    39. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    40.  
    41. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    42.  
    43. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    44.  
    45. at java.lang.reflect.Method.invoke(Method.java:601)
    46.  
    47. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    48.  
    49. ... 14 more


    Please help...
     
  2. Code:
    Caused by: java.lang.NullPointerException at com.gmail.godplaylt.myplugin.Main.onJoining(Main.java:94)
    Whatevers on that line of main is the problem. if it's one of the rnd variables you haven't initialised it probably.
     
  3. Offline

    Tomass

    Yes, the line of error is 94 and it is:
    Code:java
    1. byte c = (byte) rnd.nextInt(3);
    2.  

    Eclipse didin't get any errors. What's the problem?
     
  4. Offline

    ZeusAllMighty11

    A byte is not an integer.

    You should be using:

    Code:
    int n = new Random().nextInt(3);
     
    Tomass likes this.
  5. Offline

    Tomass

    Thank you very much. It's works! :)
     
Thread Status:
Not open for further replies.

Share This Page