"blockListener" errors

Discussion in 'Plugin Development' started by davejavu, Jan 17, 2012.

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

    davejavu

    I'm getting "blockListener cannot be resolved to a variable" - line 18
    and, "blockListener can only use final" - should I take away the "private" infront of it?
    CODE:
    Code:
    package com.github.davejavu;
     
    import java.util.logging.Logger;
     
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
     
    public class AnnoyingPlugin extends JavaPlugin{
        Logger log = Logger.getLogger("Minecraft");
        private final AnnoyingPluginBlockListener blockListener = new AnnoyingPluginBlockListener(this);    //LINE 13
     
        public void onEnable(){
            PluginManager pm = this.getServer().getPluginManager();
            log.info("Annoyer has been enabled! By davejavu");
            pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
         
        }
     
        public void onDisable(){
            log.info("Annoyer has been disabled! By davejavu");
        }
     
    }
    
     
  2. You give the BlockListener the plugin class, but since it wasn't even initialized, it's null. so put it in you onEnable function and it should work.
     
  3. Offline

    davejavu

    kumpelblase2
    Thank you! That removed the null error :)
    Now I'm getting "blockListener cannot be resolved to a variable" - line 18
    and, "blockListener can only use final" - should I take away the "private" infront of it?
     
  4. removing the private wouldn't change anything, removing the final should fix it. final prevents re-initialsing of variables.

    so:
    Code:
    final SomeClass some = new SomeClass();
    you will still be able to do like:
    Code:
    some.doSomething();
    but those things doesn't work:
    Code:
    some = someClassInstance;
    some = new SomeClass();
    hope this helps.
     
  5. Offline

    davejavu

    Could you replace the "somes" with examples, such as a player listener class, thanks for the help though!

    kumpelblase2
    And, if I remove the final, eclipse says: "Illegal modifier for parameter blockListener; only final is permitted"

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  6. It does not do so for me, so I don't know why. maybe someone else can give an (better) answer.
     
Thread Status:
Not open for further replies.

Share This Page