Solved NPE error when trying to start timer from another class...

Discussion in 'Plugin Help/Development/Requests' started by PlayFriik, Dec 25, 2014.

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

    PlayFriik

    My main class:
    Code:
    package net.playfriik.test;
    
    import net.playfriik.smash.listeners.PlayerListener;
    import net.playfriik.smash.managers.TimeManager;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin {
     
        TimeManager timer;
     
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
            timer.Timer1();
        }
     
        public void onDisable() {
    
        }
    }
     
    Last edited: Dec 25, 2014
  2. Offline

    JordyPwner

    the error and full class would be nice
     
  3. Offline

    Rocoty

  4. Offline

    PlayFriik

    Error:
    Code:
    [14:44:14 ERROR]: Error occurred while enabling Test v1.0 (Is it up to date?)
    java.lang.NullPointerException
            at net.playfriik.smash.Test.onEnable(Smash.java:18) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[S
    pigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:335) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:405) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.jav
    a:352) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.
    java:313) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:74
    1) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.Bukkit.reload(Bukkit.java:534) [Spigot.jar:git-Spigot-29db
    aa7-262c777]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:642) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [Spi
    got.jar:git-Spigot-29dbaa7-262c777]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_20]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_20]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    83) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    23) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :526) [Spigot.jar:git-Spigot-29dbaa7-262c777]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_20]
    
    And that is my full class.. If you meant my full main class.
     
    Last edited: Dec 25, 2014
  5. Offline

    mine-care

    U use a uninitialized variable (time)
     
  6. Offline

    mrCookieSlime Retired Staff

    Moved to Alternatives Section.
     
  7. Offline

    PlayFriik

    I have another NPE error now... -.-

    Main:
    Code:
    package net.playfriik.test;
    
    import net.playfriik.test.managers.TimeManager;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test extends JavaPlugin {
    
        TimeManager timer;
    
        public void onEnable() {
            this.saveDefaultConfig();
            timer = new TimeManager(this);
            this.timer.Timer1();
        }
    
        public void onDisable() {
        }
    }
    
    TimeManager:
    Code:
    package net.playfriik.test.managers;
    
    import net.playfriik.test.ActionAPI;
    import net.playfriik.test.ScoreboardAPI;
    import net.playfriik.test.Test;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    
    public class TimeManager {
    
        private Test plugin;
        int startDelay = plugin.getConfig().getInt("start-delay"); // NPE error <<<<<
        int restartDelay = plugin.getConfig().getInt("restart-delay"); // NPE error <<<<<
    
        public TimeManager(Test plugin) {
            this.plugin = plugin;
        }
    
        public void Timer1() {
            Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                    ActionAPI.sendServerAnnouncement(ChatColor.GOLD + "asd");
                }
            }, 0L, 1*20);
        }
    
    Basically, it can't find these fields at config, but I have everything done, am I right?

    FIXED, I just added these integers into my main class. :)
     
    Last edited: Dec 25, 2014
Thread Status:
Not open for further replies.

Share This Page