NullPointerException problem

Discussion in 'Plugin Development' started by TMAsantos, Oct 23, 2011.

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

    TMAsantos

    I'm having a NullPointerException problem :S
    What kind of stuff can cause this?

    Thanks
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    When you invoke a method on a null object.

    Incorrect, you can do things with null values. for instance (object == null) This will not throw a null exception error.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  3. Offline

    Jogy34

    nevermind.
     
  4. Offline

    TMAsantos

    :S
    I catch one here...

    Code:
    public class DataBase{
        public static Companies plugin;
    
        public DataBase(Companies companies) {
            plugin = companies;
        }
    
        Logger log = Logger.getLogger("Minecraft");
        protected File compFile = new File(plugin.getDataFolder(), "Companies.yml");
        protected FileConfiguration conf = YamlConfiguration.loadConfiguration(compFile);
    
        public String getCompanie(){
            return "";
        }
    
        public String getOwner(String companie){
    
            companie = companie.toUpperCase();
            companie += ".Owner";
            return plugin.getConfig().getString(companie, "");
    
        }
    
        public boolean isCompanie(String companie){
            companie = companie.toUpperCase();
            companie += ".name";
            if (companie == plugin.getConfig().getString(companie, "")){
                return true;
            }
            return false;
        }
    
        public void createCompanie(String name, String owner){
            name = name.toUpperCase();
            String originalname = name;
            try {
                log.info("[Company] Creating Company");
                name += ".name";
                plugin.getConfig().set(name, originalname);
                name = originalname;
                name += ".Owner";
                plugin.getConfig().set(name, owner);
    
                //set employees here!
    
                plugin.getConfig().save(compFile);
                } catch (IOException e) {
                    log.severe("[Company] Error creating Company!");
                }
        }
    
    }
    Im learning configs... the code might be all wrong :S

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  5. Offline

    thehutch

    Its completely wrong sorry :(
    just do what this says:
    Code:
        // decleare this in your mainclass at the top
        FileConfiguration config;
     
        // call this method in your onEnable()
        public void setupConfig() {
    
            config = this.getConfig();
    
            // fill in these addDefaults with your config values
            config.addDefault("String value here" , "Default value");
            config.addDefault();
            config.addDefault();
            config.addDefault();
            config.addDefault();
    
            config.options().copyDefaults(true);
            saveConfig();
        }
     
  6. Paste the exception, thats always the starting point to having us help :)
     
  7. Offline

    TMAsantos

    why is it wrong? i called the mains class here:
    Code:
     public DataBase(Companies companies) {
            plugin = companies;
        }
    So creating the configs on another class is the same, i think :S

    im getting InvocationTargetExeption too.

    when i comment this:
    getCommand("company").setExecutor(new Commands(this,database));
    the comand disapears...
    could the Commands Class be the problem?

    Thx

    Most of it Fixed

    Now i only get this

    Code:
    12:33:05 [SEVERE] Error occurred while enabling Companies v0.1 (Is it up to date
    ?): null
    java.lang.NullPointerException
            at me.tmasantos.Companies.Companies.onEnable(Companies.java:23)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:174)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:957)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:280)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:171)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:154
    )
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:297)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:284)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:152)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    12:33:05 [INFO] Speed enabled!
    line 23: getCommand("company").setExecutor(new Commands(this,database));

    database is where i make my configs. :S

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  8. Make sure you initialized database.
     
  9. Offline

    TMAsantos

    @ r3Fuze
    protected DataBase database = new DataBase(this);

    you can see DataBase UP (i changed some thigs, to fix some severals But basicaly is the same)

    Fixed, but now im getting:
    ArrayIndexOutOfBoundsException


    -.-


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

Share This Page