Calendar problem

Discussion in 'Spigot Plugin Development' started by JustCedric, Jun 9, 2016.

  1. Hi guys,

    I get an error when this code executes..
    If someone dies I save the date exactly 1 day later so for example a player dies on 09-06-2016 19:00 the date in the config will be 10-06-2016 19:00 and I want to check if the current date is after the date in the config, but I get this error

    CODE:
    Code (Text):
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Amsterdam"));
                    DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy HH:mm:ss");
                    dateFormat.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam"));
                    String death_end = instance.playerConfig.getString(UUID + ".die_date");
                    Date death = null;
                    try {
                        death = dateFormat.parse(death_end);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    if (cal.getTime().after(death)) {
                        instance.playerConfig.set(UUID + ".die_date", null);
                        instance.saveYml(instance.playerConfig, instance.playerYml);
                        Scoreboard(p);
                    }
    ERROR:
    Code (Text):
    java.lang.NullPointerException
            at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1439) ~[?:1.8.0_72]
            at java.text.DateFormat.parse(DateFormat.java:364) ~[?:1.8.0_72]
            at me.justcedric.mrp.events.Join$2.run(Join.java:415) ~[?:?]
            at org.bukkit.craftbukkit.v1_9_R2.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16]
            at org.bukkit.craftbukkit.v1_9_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16]
            at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:734) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16]
            at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16]
            at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16]
            at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot-1.9.4.jar:git-Spigot-4af49dc-c5e9a16]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
     
  2. NullPointerException: Most likely instance.playerConfig.getString(UUID + ".die_date"); either Instance or the config or the String is null.
     
  3. Thanks I dont get any errors rn but for some reason it gets executed when the current date is not after the date in the config?

    This is the date that gets put into config:
    die_date: 10-16-2016 19:16:19
    and it's not that date but it still gets executed..
     
  4. No idea, try some rubber duck debugging, and try some other methods.