Runnable

Discussion in 'Plugin Development' started by Henrique Loopes, Jan 4, 2015.

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

    Henrique Loopes

    entMap.representData(SafeRepresenter.java:213)
    [14:16:06 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:95)
    [14:16:06 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:65)
    [14:16:06 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:271)
    [14:16:06 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:262)
    [14:16:06 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:234)
    [14:16:06 WARN]: at org.yaml.snakeyaml.Yaml.dump(Yaml.java:209)
    [14:16:06 WARN]: at org.bukkit.configuration.file.YamlConfiguration.saveToString(YamlConfiguration.java:40)
    [14:16:06 WARN]: at org.bukkit.configuration.file.FileConfiguration.save(FileConfiguration.java:103)
    [14:16:06 WARN]: at Me.HenriqueLoopes.Streak$1.run(Streak.java:63)
    [14:16:06 WARN]: at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71)
    [14:16:06 WARN]: at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
    [14:16:06 WARN]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    [14:16:06 WARN]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    [14:16:06 WARN]: at java.lang.Thread.run(Thread.java:745)




    This error is these lines :

    private void save(){
    new BukkitRunnable() {
    public void run() {
    try{
    config.save(cfile);
    }
    catch (Exception e){
    e.printStackTrace();
    }
    }
    }.runTaskAsynchronously(Main.plugin);
    }
     
  2. Offline

    Matroy

  3. Offline

    gogobebe2

    Can you please give the full stacktrace?
     
  4. Offline

    nverdier

    @Henrique Loopes
     
  5. Offline

    Henrique Loopes

    [22:10:37 WARN]: java.lang.NullPointerException: Nodes must be provided.
    [22:10:37 WARN]: at org.yaml.snakeyaml.nodes.NodeTuple.<init>(NodeTuple.java:28)
    [22:10:37 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:168)
    [22:10:37 WARN]: at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter.java:213)
    [22:10:37 WARN]: at org.bukkit.configuration.file.YamlRepresenter$RepresentConfigurationSection.representData(YamlRepresenter.java:23)
    [22:10:37 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:95)
    [22:10:37 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:161)
    [22:10:37 WARN]: at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter.java:213)
    [22:10:37 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:95)
    [22:10:37 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:65)
    [22:10:37 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:271)
    [22:10:37 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:262)
    [22:10:37 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:234)
    [22:10:37 WARN]: at org.yaml.snakeyaml.Yaml.dump(Yaml.java:209)
    [22:10:37 WARN]: at org.bukkit.configuration.file.YamlConfiguration.saveToString(YamlConfiguration.java:40)
    [22:10:37 WARN]: at org.bukkit.configuration.file.FileConfiguration.save(FileConfiguration.java:103)
    [22:10:37 WARN]: at Me.HenriqueLoopes.StatsManager$1.run(StatsManager.java:70)
    [22:10:37 WARN]: at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71)
    [22:10:37 WARN]: at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
    [22:10:37 WARN]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    [22:10:37 WARN]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    [22:10:37 WARN]: at java.lang.Thread.run(Thread.java:745)
    [22:10:37 WARN]: java.lang.NullPointerException
    [22:10:39 WARN]: java.lang.NullPointerException: Nodes must be provided.
    [22:10:39 WARN]: at org.yaml.snakeyaml.nodes.NodeTuple.<init>(NodeTuple.java:28)
    [22:10:39 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:168)
    [22:10:39 WARN]: at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter.java:213)
    [22:10:39 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:95)
    [22:10:39 WARN]: at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:65)
    [22:10:39 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:271)
    [22:10:39 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:262)
    [22:10:39 WARN]: at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:234)
    [22:10:39 WARN]: at org.yaml.snakeyaml.Yaml.dump(Yaml.java:209)
    [22:10:39 WARN]: at org.bukkit.configuration.file.YamlConfiguration.saveToString(YamlConfiguration.java:40)
    [22:10:39 WARN]: at org.bukkit.configuration.file.FileConfiguration.save(FileConfiguration.java:103)
    [22:10:39 WARN]: at Me.HenriqueLoopes.StatsManager$1.run(StatsManager.java:70)
    [22:10:39 WARN]: at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71)
    [22:10:39 WARN]: at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
    [22:10:39 WARN]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    [22:10:39 WARN]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    [22:10:39 WARN]: at java.lang.Thread.run(Thread.java:745)
     
  6. Offline

    gogobebe2

    We also need the rest of your code. However it's definitly something to do with the config.yml.
    Null pointer exception means something is trying to access a variable that has null value when it doesn't want null value or a method or something that returns null.
     
    Last edited: Jan 4, 2015
  7. Offline

    Henrique Loopes

    this here my class :

    package Me.HenriqueLoopes;

    import java.io.File;

    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scheduler.BukkitRunnable;

    public class StatsManager
    implements Listener
    {
    private static StatsManager classe = new StatsManager();
    private Plugin p;
    private FileConfiguration config;
    private File cfile;
    public static StatsManager classe()
    {
    return classe;
    }
    public void setupkits(Plugin p)
    {
    if (!p.getDataFolder().exists()) {
    p.getDataFolder().mkdir();
    }
    cfile = new File(p.getDataFolder(), "Stats.yml");
    if (!cfile.exists()) {
    try
    {
    cfile.createNewFile();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    config = YamlConfiguration.loadConfiguration(cfile);
    }
    public int getKills(Player p)
    {
    return config.getInt(p.getName().toLowerCase() + ".kills");
    }
    public int getDeaths(Player p)
    {
    return config.getInt(p.getName().toLowerCase() + ".deaths");
    }
    public void addKills(Player p)
    {
    config.set(p.getName().toLowerCase() + ".kills", Integer.valueOf(getKills(p) + 1));
    save();
    }
    public void addDeaths(Player p)
    {
    config.set(p.getName().toLowerCase() + ".deaths", Integer.valueOf(getDeaths(p) + 1));
    save();
    }
    private void save(){
    new BukkitRunnable() {
    public void run() {
    try{
    config.save(cfile);
    }
    catch (Exception e){
    e.printStackTrace();
    }
    }
    }.runTaskAsynchronously(Main.plugin);
    }
    public Plugin getPlugin()
    {
    return this.p;
    }
    }
     
  8. Offline

    nverdier

    Doesn't have to be a variable. Could also be a method etc that returns null.
     
  9. Offline

    Henrique Loopes

    o'que I do to fix? Please help me!
     
  10. Offline

    timtower Moderator Moderator

    Moved to plugin development
     
  11. Offline

    Danteland

    Is yamlconfig threadsafe? Maybe he is trying to save something that hasn't been assigned a value yet

    What i once encountered was that my config didn't save when I made a seperate method that that was used to save the configfile. Instead of running it in a new thread, remove the save() method and save the file within the method where you set the kills.
    Or if its a performance issue you can run that entire method in a new thread
     
    Last edited: Jan 5, 2015
    gogobebe2 likes this.
  12. Offline

    Henrique Loopes

    Thank You!
     
    gogobebe2 likes this.
  13. Offline

    Danteland

    What?, Did i solve it?
     
    gogobebe2 likes this.
  14. Offline

    Henrique Loopes

Thread Status:
Not open for further replies.

Share This Page