Trying to connect to MySQL

Discussion in 'Spigot Plugin Development' started by GoRoK, Jun 28, 2016.

  1. Getting this Error:
    Code (Text):

    [16:51:35 ERROR]: Error occurred while enabling Nirox_GunGame v1.0.0 (Is it up to date?)
    java.lang.NullPointerException
            at openinventory.pack.Ranging.set(Ranging.java:27) ~[?:?]
            at openinventory.pack.Main.onEnable(Main.java:15) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:746) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:632) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
     
    Thats on Line 27 (method)
    Code (Text):

    public void connect() {
            try {
                con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
                System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
            } catch (SQLException e) {
                System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
            }
        }
     
    Im trying to Connect to the Server "localhost" (the MySQL isn't configured for external connections.)
    The MySQL and the Server are on the same Server. Trying to get into database "testbase" picture from phpMyadmin https://gyazo.com/f01e3c4dcfca903a444ea5bcc5ceed8d

    User and password are correct.
    Im new to MySQL soo..
    Line 15 in Main is:
    Code (Text):

    Ranging.set();
     
    Which is
    Code (Text):

    @SuppressWarnings("deprecation")
        public static void set()
        {
            ResultSet rs = Main.mysql.query("SELECT UUID FROM Stats ORDER BY Kills DESC LIMIT 3");
            int in = 0;
            try {
                while(rs.next())
                {
                    in++;
                    rang.put(in, rs.getString("UUID"));
                }
               
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
           
            Location loc = new Location(Bukkit.getWorld("world"), 23, 11, 3);
            Location loc1 = new Location(Bukkit.getWorld("world"), 22, 11, 3);
            Location loc11 = new Location(Bukkit.getWorld("world"), 24, 11, 3);
            Location loc111 = new Location(Bukkit.getWorld("world"), 25, 11, 3);
            List<Location> LOC = new ArrayList<>();
            LOC.add(loc);
            LOC.add(loc111);
            LOC.add(loc11);
            LOC.add(loc1);
           
           
           
           
           
           
            for(int i = 0; i < LOC.size(); i++)
            {
                int id = i+1;
               
               
               
                LOC.get(i).getBlock().setType(Material.SKULL);
                Skull s = (Skull) LOC.get(i).getBlock().getState();
                s.setSkullType(SkullType.PLAYER);
                String name = String.valueOf(Bukkit.getPlayer(UUID.fromString(rang.get(id))));
                s.setOwner(name);
                s.update();
               
                Location newloc = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY() - 1, LOC.get(i).getZ());
                if(newloc.getBlock().getState() instanceof Sign)
                   
                {
                    BlockState b = newloc.getBlock().getState();
                    Sign sign = (Sign) b;
                    sign.setLine(0, "Platz #" + id);
                    sign.setLine(1, name);
                    sign.setLine(2, "");
                    sign.setLine(3, SQLStats.getKills(rang.get(id)) / SQLStats.getDeaths(rang.get(id)) +  " K/D");
                    sign.update();
                }
            }
           
        }
    }
     
    Thanks for any help..
     
  2. MiniDigger

    Supporter

    your connection method looks fine
    can you point us the exact line "at openinventory.pack.Ranging.set(Ranging.java:27)"
    because thats where you access a null value.
     
  3. Code (Text):
         ResultSet rs = Main.mysql.query("SELECT UUID FROM Stats ORDER BY Kills DESC LIMIT 3");
     
  4. MiniDigger

    Supporter

    thats null, go check why.
     
  5. Fixed that, other error occurs
    Code (Text):


    [15:35:26 ERROR]: Error occurred while enabling Nirox_GunGame v1.0.0 (Is it up to date?)
    java.lang.NullPointerException
            at openinventory.pack.Ranging.set(Ranging.java:30) ~[?:?]
            at openinventory.pack.Main.onEnable(Main.java:15) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]

     
    Line 15:
    Code (Text):

    Ranging.set();
     
    Line 30:
    Code (Text):

    public static void set()
        {
            ResultSet rs = Main.mysql.query("SELECT UUID FROM Stats ORDER BY Kills DESC LIMIT 3");
            int in = 0;
            try {
                while(rs.next()) <-------- 30
                {
                    in++;
                    rang.put(in, rs.getString("UUID"));
                }
           
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
       
       
            Location loc = new Location(Bukkit.getWorld("world"), 23, 11, 3);
            Location loc1 = new Location(Bukkit.getWorld("world"), 22, 11, 3);
            Location loc11 = new Location(Bukkit.getWorld("world"), 24, 11, 3);
            Location loc111 = new Location(Bukkit.getWorld("world"), 25, 11, 3);
            List<Location> LOC = new ArrayList<>();
            LOC.add(loc);
            LOC.add(loc111);
            LOC.add(loc11);
            LOC.add(loc1);
       
       
       
       
       
       
            for(int i = 0; i < LOC.size(); i++)
            {
                int id = i+1;
           
           
           
                LOC.get(i).getBlock().setType(Material.SKULL);
                Skull s = (Skull) LOC.get(i).getBlock().getState();
                s.setSkullType(SkullType.PLAYER);
                String name = String.valueOf(Bukkit.getPlayer(UUID.fromString(rang.get(id))));
                s.setOwner(name);
                s.update();
           
                Location newloc = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY() - 1, LOC.get(i).getZ());
                if(newloc.getBlock().getState() instanceof Sign)
               
                {
                    BlockState b = newloc.getBlock().getState();
                    Sign sign = (Sign) b;
                    sign.setLine(0, "Platz #" + id);
                    sign.setLine(1, name);
                    sign.setLine(2, "");
                    sign.setLine(3, SQLStats.getKills(rang.get(id)) / SQLStats.getDeaths(rang.get(id)) +  " K/D");
                    sign.update();
                }
            }
       
        }
    }
     
    The Server is getting connected to the DB [text]
    [MySQL] Die Verbindung zur MySQL wurde hergestellt!
    [/text]
    Which is defined after successful connection, the Problem must be in the Ranging class, full code:
    Code (Text):

    package openinventory.pack;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.SkullType;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    import org.bukkit.block.Skull;

    import me.API.SQLStats;

    public class Ranging
    {
        public static HashMap<Integer, String> rang = new HashMap<Integer, String>();
       
        @SuppressWarnings("deprecation")
        public static void set()
        {
            ResultSet rs = Main.mysql.query("SELECT UUID FROM Stats ORDER BY Kills DESC LIMIT 3");
            int in = 0;
            try {
                while(rs.next())
                {
                    in++;
                    rang.put(in, rs.getString("UUID"));
                }
               
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
           
            Location loc = new Location(Bukkit.getWorld("world"), 23, 11, 3);
            Location loc1 = new Location(Bukkit.getWorld("world"), 22, 11, 3);
            Location loc11 = new Location(Bukkit.getWorld("world"), 24, 11, 3);
            Location loc111 = new Location(Bukkit.getWorld("world"), 25, 11, 3);
            List<Location> LOC = new ArrayList<>();
            LOC.add(loc);
            LOC.add(loc111);
            LOC.add(loc11);
            LOC.add(loc1);
           
           
           
           
           
           
            for(int i = 0; i < LOC.size(); i++)
            {
                int id = i+1;
               
               
               
                LOC.get(i).getBlock().setType(Material.SKULL);
                Skull s = (Skull) LOC.get(i).getBlock().getState();
                s.setSkullType(SkullType.PLAYER);
                String name = String.valueOf(Bukkit.getPlayer(UUID.fromString(rang.get(id))));
                s.setOwner(name);
                s.update();
               
                Location newloc = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY() - 1, LOC.get(i).getZ());
                if(newloc.getBlock().getState() instanceof Sign)
                   
                {
                    BlockState b = newloc.getBlock().getState();
                    Sign sign = (Sign) b;
                    sign.setLine(0, "Platz #" + id);
                    sign.setLine(1, name);
                    sign.setLine(2, "");
                    sign.setLine(3, SQLStats.getKills(rang.get(id)) / SQLStats.getDeaths(rang.get(id)) +  " K/D");
                    sign.update();
                }
            }
           
        }
    }

     
     
  6. Forgot to create the Table ._.
    The Error now
    Code (Text):

    [15:47:54 ERROR]: Error occurred while enabling Nirox_GunGame v1.0.0 (Is it up to date?)
    java.lang.NullPointerException
            at java.util.UUID.fromString(UUID.java:192) ~[?:1.8.0_77]
            at openinventory.pack.Ranging.set(Ranging.java:66) ~[?:?]
            at openinventory.pack.Main.onEnable(Main.java:15) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]

     
    I need an alternative for:
    Code (Text):
     String name = String.valueOf(Bukkit.getPlayer(UUID.fromString(rang.get(id))));
    Complete class again
    Code (Text):

    package openinventory.pack;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.SkullType;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    import org.bukkit.block.Skull;

    import me.API.SQLStats;

    public class Ranging
    {
        public static HashMap<Integer, String> rang = new HashMap<Integer, String>();
       
        @SuppressWarnings("deprecation")
        public static void set()
        {
            ResultSet rs = Main.mysql.query("SELECT UUID FROM Stats ORDER BY Kills DESC LIMIT 3");
            int in = 0;
            try {
                while(rs.next())
                {
                    in++;
                    rang.put(in, rs.getString("UUID"));
                }
               
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
           
            Location loc = new Location(Bukkit.getWorld("world"), 23, 11, 3);
            Location loc1 = new Location(Bukkit.getWorld("world"), 22, 11, 3);
            Location loc11 = new Location(Bukkit.getWorld("world"), 24, 11, 3);
            Location loc111 = new Location(Bukkit.getWorld("world"), 25, 11, 3);
            List<Location> LOC = new ArrayList<>();
            LOC.add(loc);
            LOC.add(loc111);
            LOC.add(loc11);
            LOC.add(loc1);
           
           
           
           
           
           
            for(int i = 0; i < LOC.size(); i++)
            {
                int id = i+1;
               
               
               
                LOC.get(i).getBlock().setType(Material.SKULL);
                Skull s = (Skull) LOC.get(i).getBlock().getState();
                s.setSkullType(SkullType.PLAYER);
                String name = String.valueOf(Bukkit.getPlayer(UUID.fromString(rang.get(id))));
                s.setOwner(name);
                s.update();
               
                Location newloc = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY() - 1, LOC.get(i).getZ());
                if(newloc.getBlock().getState() instanceof Sign)
                   
                {
                    BlockState b = newloc.getBlock().getState();
                    Sign sign = (Sign) b;
                    sign.setLine(0, "Platz #" + id);
                    sign.setLine(1, name);
                    sign.setLine(2, "");
                    sign.setLine(3, SQLStats.getKills(rang.get(id)) / SQLStats.getDeaths(rang.get(id)) +  " K/D");
                    sign.update();
                }
            }
           
        }
    }

     
     
  7. Forgot the query part...
    Code (Text):

    public ResultSet query(String qry) {
            ResultSet rs = null;
           
            try {
                Statement st = con.createStatement();
                rs = st.executeQuery(qry);
            } catch (SQLException e) {
                connect();
                System.err.println(e);
            }
            return rs;
        }
    }
     
    Doenst work as well
     
  8. This should work:
    Code (Text):
    String name = Bukkit.getPlayer(UUID.fromString(rang.get(id))).getName();
     
  9. @GoRoK not clinging to static would be wise, and save you a lot of those NullPointerExceptions. Moreover, you should pick a better package name.

    As for solving error, read their stack trace.

    And don't triple post please, just edit your previous post if there haven't been any new posts.
     
  10. The Method of @phil14052 doesnt work as well...
    Code (Text):

    for(int i = 0; i < LOC.size(); i++)
            {
                int id = i+1;
               
               
               
                LOC.get(i).getBlock().setType(Material.SKULL);
                Skull s = (Skull) LOC.get(i).getBlock().getState();
                s.setSkullType(SkullType.PLAYER);
                String name = Bukkit.getPlayer(UUID.fromString(rang.get(id))).getDisplayName(); <-- Error
                s.setOwner(name);
                s.update();
               
                Location newloc = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY() - 1, LOC.get(i).getZ());
                if(newloc.getBlock().getState() instanceof Sign)
                   
                {
                    BlockState b = newloc.getBlock().getState();
                    Sign sign = (Sign) b;
                    sign.setLine(0, "Platz #" + id);
                    sign.setLine(1, name);
                    sign.setLine(2, "");
                    sign.setLine(3, SQLStats.getKills(rang.get(id)) / SQLStats.getDeaths(rang.get(id)) +  " K/D");
                    sign.update();
                }
            }
           
        }
    }

     
    Error:
    Code (Text):

    [19:13:48 ERROR]: Error occurred while enabling Nirox_GunGame v1.0.0 (Is it up to date?)
    java.lang.NullPointerException
            at java.util.UUID.fromString(UUID.java:192) ~[?:1.8.0_77]
            at openinventory.pack.Ranging.set(Ranging.java:67) ~[?:?]
            at openinventory.pack.Main.onEnable(Main.java:15) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
     
    Everything is just based on that above.. If im not completly wrong..
     
  11. First: The s.setOwner() requires the name of the player not the displayname. So use player#getName().
    If I was you I would debug the code.
    Try putting this before:
    Code (Text):
    MAINCLASS.getLogger().info(rang.get(id));
    Or something like that.
    But do as @DarkSeraphim said first.