[HELP] i have a problem saving files from my workspace

Discussion in 'Spigot Plugin Development' started by Yazio, Jul 11, 2015.

  1. i have tried some ways but it doesn't work here is my current code
    PHP:
    InputStream readConfig = getResource("messages.yml");
            YamlConfiguration setDefaults = new YamlConfiguration().loadConfiguration(readConfig);
            if(!settings.dfile.exists()) {
                settings.getData().addDefaults(setDefaults);
                settings.getData().options().copyDefaults(true);
            }
    settings manager
    PHP:
    Plugin p;
        File dfile = new File(p.getDataFolder(), "messages.yml");
        FileConfiguration data = YamlConfiguration.loadConfiguration(dfile);
       
        public FileConfiguration getData() {
            return data;
        }
    error
    PHP:
    Caused by: java.lang.InstantiationException: Tokens.Main
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_40]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-"8c26a90"]
            ... 7 more
    Caused by: java.lang.NoSuchMethodException: Tokens.Main.<init>()
            at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_40]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_40]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-"8c26a90"]
            ... 7 more
    if you know this problem please help :p
     
  2. Creeoer

    Supporter

    Did you even initialize p (Your plugin). Is it in the constructor?
     
  3. woops ill try that out xD
     
    • Funny Funny x 1
  4. didn't work... :( also tried out some other things but they didn't work

    changed code
    PHP:
    Main p;
    File dfile = new File(p.getDataFolder(), "messages.yml");
     
  5. Creeoer

    Supporter

    What is p equal to? Do you have anything like
    your constructor(Main instance){
    p = instance;
    }
     
  6. no
     
  7. Creeoer

    Supporter

    Then obviously you'll get an error as your plugin instance is null.
     
  8. i have tried this
    PHP:
    private final Main p;
        public SettingsManager(Main p) {
            this.p = p;
        }
    gives me an error with p.getDataFolder() (the blank final field p may not have been initialized)
    then i have tried without the final and it gives me the same error (the error from the top) ...
    i have also tried to do
    settings manager
    PHP:
    Main p = Main.getInstance();
    File dfile = new File(p.getDataFolder(), "messages.yml");
    main
    PHP:
    static Main instance = new Main();
    public static Main getInstance() {
            return instance;
        }
    gives the same error
     
  9. Creeoer

    Supporter

    In the last bit you are instaintiating another Main, which is a big no no. Bukkit already instantiates it in the onEnable, put this in your onEnable

    public static Main instance;

    public void onEnable(){
    instance = this;
    }
     
  10. i don't see why this really doesn't work i have tried this but that didn't work either
    new code
    PHP:
    private Tokens p;
       
        public SettingsManager(Tokens p) {
            this.p = p;
        }
       
        File dfile = new File(p.getDataFolder(), "messages.yml");
     
  11. Have you tried

    Code (Text):
    Tokens t = new Tokens();
    Or maybe changing it from private?

    And also... You went completely off course from the previous message, the other guy is talking about getting the Main instance and all of a sudden your talking about a whole different class now, try to focus on one thing at a time, make sure that you can get getting the instance of main working, then worry about getting the other classes
     
  12. yes