NullPointerException

Discussion in 'Plugin Development' started by DevAPI, Nov 17, 2019.

  1. Offline

    DevAPI

    Hello I'm new to coding and I am making my own rank system using Redis to store data my IDE shows no errors but when I try to enable my plugin in the server it does not work.

    Stack Trace (open)

    17.11 15:26:22 [Server] INFO java.lang.NullPointerException 17.11 15:26:22 [Server] INFO at us.gempvp.core.Core.setupJedis(Core.java:92) ~[?:?] 17.11 15:26:22 [Server] INFO at us.gempvp.core.Core.onEnable(Core.java:41) ~[?:?] 17.11 15:26:22 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:412) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:476) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:394) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:360) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:334) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:290) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:210) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:458) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 17.11 15:26:22 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]


    Code:
    package us.gempvp.core;
    
    import org.bukkit.plugin.java.*;
    
    import redis.clients.jedis.*;
    import us.gempvp.core.grant.*;
    import us.gempvp.core.grant.procedure.*;
    import us.gempvp.core.jedis.*;
    import us.gempvp.core.profile.*;
    import us.gempvp.core.profile.command.*;
    import us.gempvp.core.rank.*;
    import us.gempvp.core.rank.command.*;
    import us.gempvp.core.rank.command.grant.*;
    import us.gempvp.core.util.*;
    import us.gempvp.core.util.command.*;
    import us.gempvp.core.util.database.*;
    import us.gempvp.core.util.file.*;
    
    import org.bukkit.entity.*;
    
    import java.util.*;
    import org.bukkit.*;
    import org.bukkit.event.*;
    import org.bukkit.plugin.*;
    
    public class Core extends JavaPlugin
    {
        private static Core instance;
        private CommandFramework commandFramework;
        private ConfigFile configFile;
        private ConfigFile ranksFile;
        private RankHandler rankHandler;
        private String address;
        private int port;
        private JedisPool pool;
        private JedisPublisher publisher;
        private JedisSubscriber subscriber;
        private PermissionsDatabase permissionsDatabase;
       
        public void onEnable() {
            Core.instance = this;
            this.configFile = new ConfigFile(this, "config");
            this.ranksFile = new ConfigFile(this, "ranks");
            this.commandFramework = new CommandFramework(this);
            this.setupJedis();
            /////
            System.out.println("[Redis] Connected and stable");
            this.registerCommands();
            this.registerListeners();
            this.permissionsDatabase = new PermissionsDatabase(this);
            this.rankHandler = new RankHandler(this);
            for (final Player online : PlayerUtility.getOnlinePlayers()) {
                new Profile(online.getUniqueId(), new ArrayList<String>(), new ArrayList<Grant>()).asyncLoad();
            }
        }
       
        public void onDisable() {
            this.subscriber.getJedisPubSub().unsubscribe();
            this.pool.destroy();
            for (final Profile profile : Profile.getProfiles()) {
                if (profile.getPlayer() != null) {
                    profile.getPlayer().removeAttachment(profile.getAttachment());
                }
                profile.save();
            }
            this.rankHandler.save();
            this.permissionsDatabase.getClient().close();
        }
       
        private void registerListeners() {
            final PluginManager pluginManager = Bukkit.getPluginManager();
            pluginManager.registerEvents((Listener)new GrantProcedureListeners(), (Plugin)this);
            pluginManager.registerEvents((Listener)new ProfileListeners(), (Plugin)this);
            pluginManager.registerEvents((Listener)new GrantListeners(), (Plugin)this);
        }
       
        private void registerCommands() {
            new RankCreateCommand();
            new RankDeleteCommand();
            new RankPrefixCommand();
            new RankSuffixCommand();
            new RankImportCommand();
            new RankAddPermissionCommand();
            new RankDeletePermissionCommand();
            new RankListPermissionsCommand();
            new ProfileAddPermissionCommand();
            new ProfileDeletePermissionCommand();
            new ProfileListPermissionsCommand();
            new GrantCommand();
            new GrantsCommand();
        }
       
        public void setupJedis() {
            this.address = this.configFile.getString("DATABASE.REDIS.HOST");
            this.port = this.configFile.getInt("DATABASE.REDIS.PORT");
            this.pool = new JedisPool(this.address, this.port);
            this.publisher = new JedisPublisher(this);
            this.subscriber = new JedisSubscriber(this);
        }
       
        public static Core getInstance() {
            return Core.instance;
        }
       
        public CommandFramework getCommandFramework() {
            return this.commandFramework;
        }
       
        public ConfigFile getConfigFile() {
            return this.configFile;
        }
       
        public ConfigFile getRanksFile() {
            return this.ranksFile;
        }
       
        public RankHandler getRankHandler() {
            return this.rankHandler;
        }
       
        public String getAddress() {
            return this.address;
        }
       
        public int getPort() {
            return this.port;
        }
       
        public JedisPool getPool() {
            return this.pool;
        }
       
        public JedisPublisher getPublisher() {
            return this.publisher;
        }
       
        public JedisSubscriber getSubscriber() {
            return this.subscriber;
        }
       
        public PermissionsDatabase getPermissionsDatabase() {
            return this.permissionsDatabase;
        }
    }
    
    
     
    Last edited: Nov 17, 2019
  2. Offline

    KarimAKL

    @DevAPI You call the method 'setupJedis()' before you initialize 'configFile', which means that calling 'getString(String)' on 'configFile' throws a NullPointerException.
     
  3. Offline

    DevAPI

    Ok I fixed that updated the code but now I get another error
    @KarimAKL

    Code:
    17.11 21:56:53 [Server] Startup [02:56:53 ERROR]: Error occurred while enabling gCore v1.0.0 (Is it up to date?)
    17.11 21:56:53 [Server] INFO java.lang.NoClassDefFoundError: redis/clients/jedis/JedisPool
    17.11 21:56:53 [Server] INFO at us.gempvp.core.Core.setupJedis(Core.java:96) ~[?:?]
    17.11 21:56:53 [Server] INFO at us.gempvp.core.Core.onEnable(Core.java:45) ~[?:?]
    17.11 21:56:53 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:412) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:476) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:394) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:360) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:334) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:290) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:210) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:458) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO Caused by: java.lang.ClassNotFoundException: redis.clients.jedis.JedisPool
    17.11 21:56:53 [Server] INFO at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_222]
    17.11 21:56:53 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[custom.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    17.11 21:56:53 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_222]
    17.11 21:56:53 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_222]
    17.11 21:56:53 [Server] INFO ... 13 more
     
  4. Offline

    KarimAKL

    @DevAPI Maybe this helps? Btw, please don't send me PMs about this thread, i'll come to it when i wake up from my slumber. :7
    If that doesn't help, try using your preferred search engine to look for an answer.
     
  5. Offline

    DevAPI

    Sorry I was just trying to get help thanks I think I have fixed it by using intelji and putting my libraries into my core
     

Share This Page