No Class Found Exception

Discussion in 'Plugin Development' started by elementalgodz11, Jan 13, 2014.

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

    elementalgodz11

    I have setup a command, but for some reason it occasionally returns a "noclassdeffound error";

    I don't know what could be causing this, I have checked line 426 (the line the error is supposedly at) and don't see anything wrong;

    Line 426:
    Code:
    this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(dkKitsMain.inst, new Runnable() {
    How I have setup the task;
    Code:
    int task;
    The error:
    ez.png

    Let me know if any more code is needed.

    Thanks.
     
  2. Offline

    Timbals

    What is dkKitsMain.inst ?
    It looks like an static type. I think static Plugins do not work with Scheduler
     
  3. Offline

    elementalgodz11

    It's a static reference to my main class.
    public static dkKitsMain inst;
    inst = this

    If so, how would I go about doing this?
    Timbals
     
  4. Offline

    LucasEmanuel

    As far as I know, statics can't return "this" since they aren't really "owned" by any object instantiated from their class.
     
  5. Offline

    jacklin213

    Change the reference to either private or public and do something like this

    Code:
    private Mainclass plugin;
    
    public classmame(Mainclass instance){
        plugin = instance;
    }
     
  6. Offline

    Not2EXceL

    Pass the instance to your command class. It takes an extra like 1 line

    And god your naming conventions are just horrible
     
  7. Offline

    elementalgodz11

    jacklin213

    Thank you, how would I get the Main class in other plugins?

    I am also getting this warning:
    "The value of the field dkKitsMain.plugin is not used"

    I'm guessing I just use plugin = this; ?
     
  8. Offline

    jacklin213

    show me an example of what u mean (screenshot) works too
     
  9. Offline

    Jake6177

    If you want to use static, make something like this in your main class:
    Code:java
    1. public static <PluginName> plugin;
    2.  
    3. @Override
    4. public void onEnable() {
    5. plugin = this;
    6. }
    7.  
    8. public static <PluginName> getInstance() {
    9. return plugin;
    10. }


    Then in the place where you need to use your main class (e.g. get logger or what not):
    Code:java
    1. private static <PluginName> plugin = <PluginName>.getInstance();
    2. plugin.getLogger().info("Static");
     
  10. Jake6177

    The "this" keyword cannot be used in a static method.
     
    Jake6177 likes this.
  11. Offline

    Jake6177

Thread Status:
Not open for further replies.

Share This Page