Singleton strange NullPointer

Discussion in 'Spigot Plugin Help' started by dallabonalucas, Jul 11, 2015.

  1. Hi spigot community, i'm making an API and i'm having some problems with Singleton classes. I have a MySQLManager class that is singleton, and a ApiManager class that is singleton too. If i get the MySQLManager directly (like MySQLManager.getSqlManager()) everything works, but if i get the manager through the ApiManager class (like ApiManager.getApiManager().getMySqlManager() that returns Null.

    Thank you!

    MySQLManager class
    Code (Text):
        private boolean connected = true;
        private MySQLConnectionPool pool;
        private static MySQLManager mysqlManager;
     
        private MySQLManager( )
        {
     
            try {
                     this.pool = new MySQLConnectionPool(ConfigManager.getConfig() .getString("Mysql.url"),
                     ConfigManager.getConfig().getString("Mysql.user") ,
                     ConfigManager.getConfig().getString("Mysql.pass") );
                } catch (ClassNotFoundException e)      
                    {              
                        e.printStackTrace();
                    }  
        }
     
        public static MySQLManager getSqlManager()
        {
            if(mysqlManager == null) mysqlManager = new MySQLManager();
            return mysqlManager;
        }
    And here the ApiManager class
    Code (Text):
        public MySQLManager getMySqlManager()
        {
            return MySQLManager.getSqlManager();
        }