Solved NullPointer Help

Discussion in 'Plugin Development' started by IcyRelic, Jul 30, 2013.

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

    IcyRelic

    im getting this error

    Code:
    01:11:08 [INFO] IcyRelic issued server command: /unban test
    01:11:08 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'unba
    n' in plugin LegendaryBans v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    9)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerCon
    nection.java:964)
            at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.j
    ava:882)
            at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java
    :839)
            at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
            at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java
    :118)
            at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    90)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.NullPointerException
            at me.icyrelic.com.Data.LBMySQL.checkBan(LBMySQL.java:170)
            at me.icyrelic.com.Commands.unban.onCommand(unban.java:34)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 15 more
    >
    LBMySQL.java:170
    Code:java
    1. rs = st.executeQuery("SELECT * FROM banlist WHERE username = '"+name+"'");


    unban.java:34
    Code:java
    1. if(mysql.checkBan(player)){


    mysql variable in unban
    Code:java
    1. private LBMySQL mysql = new LBMySQL();



    checkban method in LBMySQL
    Code:java
    1. public boolean checkBan(String name){
    2.  
    3.  
    4. try {
    5.  
    6. rs = st.executeQuery("SELECT * FROM banlist WHERE username = '"+name+"'");
    7.  
    8. if (rs.next()) {
    9. return true;
    10. }else{
    11. return false;
    12. }
    13.  
    14.  
    15. } catch (SQLException ex) {
    16. return false;
    17.  
    18. }
    19.  
    20. }
     
  2. Offline

    Alex5657

    Full code please. What is rs? What is st?
     
  3. Offline

    IcyRelic

    the code is about 700 lines long anyway those are

    Statement and ResultSet the class worked fine when i had it like this

    i had this in the main class

    Code:java
    1. public LBMySQL mysql = new LBMySQL(this);


    and had this in the mysql class at the top

    Code:java
    1. LegendaryBans plugin;
    2. public LBMySQL(LegendaryBans instance) {
    3. plugin = instance;
    4. }



    i removed both of those and made the variable private and added it to every class that needed myql and now it wont work

    and in the classes to access the mysql i used plugin.mysql and that worked fine

    fixed it!

    i made the connection to the database, resultset, and statement static

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page