Solved java.lang.NullPointerException error

Discussion in 'Spigot Plugin Help' started by GekkeStef, May 24, 2016.

  1. So... third time on here,
    but yea i got another error!
    [15:59:33] [Server thread/INFO]: Starting minecraft server version 1.8
    [15:59:33] [Server thread/INFO]: Loading properties
    [15:59:33] [Server thread/INFO]: Default game type: CREATIVE
    [15:59:33] [Server thread/INFO]: This server is running CraftBukkit version git-Spigot-550ebac-7019900 (MC: 1.8) (Implementing API version 1.8-R0.1-SNAPSHOT)
    [15:59:33] [Server thread/INFO]: Debug logging is disabled
    [15:59:33] [Server thread/INFO]: Server Ping Player Sample Count: 12
    [15:59:33] [Server thread/INFO]: Using 4 threads for Netty based IO
    [15:59:33] [Server thread/INFO]: Generating keypair
    [15:59:33] [Server thread/INFO]: Starting Minecraft server on *:25565
    [15:59:33] [Server thread/INFO]: Set PluginClassLoader as parallel capable
    [15:59:33] [Server thread/ERROR]: Could not load 'plugins\EScoreBoard - Custom.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot.jar:git-Spigot-550ebac-7019900]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-550ebac-7019900]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-550ebac-7019900]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:291) [spigot.jar:git-Spigot-550ebac-7019900]
    at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:152) [spigot.jar:git-Spigot-550ebac-7019900]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [spigot.jar:git-Spigot-550ebac-7019900]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
    at com.mienka.escoreboards.Main.<init>(Main.java:34) ~[?:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_91]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_91]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_91]
    at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_91]
    at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_91]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-550ebac-7019900]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-550ebac-7019900]
    ... 6 more
    [15:59:33] [Server thread/INFO]: [Essentials] Loading Essentials vTeamCity
    [15:59:33] [Server thread/INFO]: [EssentialsSpawn] Loading EssentialsSpawn vTeamCity
    [15:59:33] [Server thread/INFO]: **** Beginning UUID conversion, this may take A LONG time ****
    [15:59:33] [Server thread/INFO]: Preparing level "world"
    [15:59:34] [Server thread/INFO]: -------- World Settings For [world] --------
    [15:59:34] [Server thread/INFO]: Item Despawn Rate: 6000
    [15:59:34] [Server thread/INFO]: Item Merge Radius: 2.5
    [15:59:34] [Server thread/INFO]: View Distance: 10
    [15:59:34] [Server thread/INFO]: Experience Merge Radius: 3.0
    [15:59:34] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [15:59:34] [Server thread/INFO]: Clear tick list: false
    [15:59:34] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [15:59:34] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [15:59:34] [Server thread/INFO]: Custom Map Seeds: Village: 10387312 Feature: 14357617
    [15:59:34] [Server thread/INFO]: Max Entity Collisions: 8
    [15:59:34] [Server thread/INFO]: Random Lighting Updates: false
    [15:59:34] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [15:59:34] [Server thread/INFO]: Mob Spawn Range: 4
    [15:59:34] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Cane Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Melon Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [15:59:34] [Server thread/INFO]: Anti X-Ray: true
    [15:59:34] [Server thread/INFO]: Engine Mode: 1
    [15:59:34] [Server thread/INFO]: Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [15:59:34] [Server thread/INFO]: Replace Blocks: [1, 5]
    [15:59:34] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [15:59:34] [Server thread/INFO]: Alternative Hopper Ticking: false
    [15:59:34] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [15:59:34] [Server thread/INFO]: Structure Info Saving: true
    [15:59:34] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [15:59:34] [Server thread/INFO]: Sending up to 10 chunks per packet
    [15:59:34] [Server thread/INFO]: Max TNT Explosions: 100
    [15:59:34] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [15:59:34] [Server thread/INFO]: -------- World Settings For [world_nether] --------
    [15:59:34] [Server thread/INFO]: Item Despawn Rate: 6000
    [15:59:34] [Server thread/INFO]: Item Merge Radius: 2.5
    [15:59:34] [Server thread/INFO]: View Distance: 10
    [15:59:34] [Server thread/INFO]: Experience Merge Radius: 3.0
    [15:59:34] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [15:59:34] [Server thread/INFO]: Clear tick list: false
    [15:59:34] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [15:59:34] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [15:59:34] [Server thread/INFO]: Custom Map Seeds: Village: 10387312 Feature: 14357617
    [15:59:34] [Server thread/INFO]: Max Entity Collisions: 8
    [15:59:34] [Server thread/INFO]: Random Lighting Updates: false
    [15:59:34] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [15:59:34] [Server thread/INFO]: Mob Spawn Range: 4
    [15:59:34] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Cane Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Melon Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [15:59:34] [Server thread/INFO]: Anti X-Ray: true
    [15:59:34] [Server thread/INFO]: Engine Mode: 1
    [15:59:34] [Server thread/INFO]: Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [15:59:34] [Server thread/INFO]: Replace Blocks: [1, 5]
    [15:59:34] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [15:59:34] [Server thread/INFO]: Alternative Hopper Ticking: false
    [15:59:34] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [15:59:34] [Server thread/INFO]: Structure Info Saving: true
    [15:59:34] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [15:59:34] [Server thread/INFO]: Sending up to 10 chunks per packet
    [15:59:34] [Server thread/INFO]: Max TNT Explosions: 100
    [15:59:34] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [15:59:34] [Server thread/INFO]: -------- World Settings For [world_the_end] --------
    [15:59:34] [Server thread/INFO]: Item Despawn Rate: 6000
    [15:59:34] [Server thread/INFO]: Item Merge Radius: 2.5
    [15:59:34] [Server thread/INFO]: View Distance: 10
    [15:59:34] [Server thread/INFO]: Experience Merge Radius: 3.0
    [15:59:34] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [15:59:34] [Server thread/INFO]: Clear tick list: false
    [15:59:34] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [15:59:34] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [15:59:34] [Server thread/INFO]: Custom Map Seeds: Village: 10387312 Feature: 14357617
    [15:59:34] [Server thread/INFO]: Max Entity Collisions: 8
    [15:59:34] [Server thread/INFO]: Random Lighting Updates: false
    [15:59:34] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [15:59:34] [Server thread/INFO]: Mob Spawn Range: 4
    [15:59:34] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Cane Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Melon Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [15:59:34] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [15:59:34] [Server thread/INFO]: Anti X-Ray: true
    [15:59:34] [Server thread/INFO]: Engine Mode: 1
    [15:59:34] [Server thread/INFO]: Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [15:59:34] [Server thread/INFO]: Replace Blocks: [1, 5]
    [15:59:34] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [15:59:34] [Server thread/INFO]: Alternative Hopper Ticking: false
    [15:59:34] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [15:59:34] [Server thread/INFO]: Structure Info Saving: true
    [15:59:34] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [15:59:34] [Server thread/INFO]: Sending up to 10 chunks per packet
    [15:59:34] [Server thread/INFO]: Max TNT Explosions: 100
    [15:59:34] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [15:59:34] [Server thread/INFO]: Preparing start region for level 0 (Seed: 8714255893563333929)
    [15:59:34] [Server thread/INFO]: Preparing start region for level 1 (Seed: 8714255893563333929)
    [15:59:35] [Server thread/INFO]: Preparing start region for level 2 (Seed: 8714255893563333929)
    [15:59:35] [Server thread/INFO]: [Essentials] Enabling Essentials vTeamCity
    [15:59:35] [Server thread/INFO]: Bukkit version format changed. Version not checked.
    [15:59:35] [Server thread/INFO]: git-Spigot-550ebac-7019900 (MC: 1.8)
    [15:59:35] [Server thread/INFO]: 1.8-R0.1-SNAPSHOT
    [15:59:35] [Server thread/INFO]: Using locale en_US
    [15:59:35] [Server thread/INFO]: Using locale en_US
    [15:59:35] [Server thread/INFO]: Essentials: Using config file enhanced permissions.
    [15:59:35] [Server thread/INFO]: Permissions listed in as player-commands will be given to all users.
    [15:59:35] [Server thread/INFO]: [EssentialsSpawn] Enabling EssentialsSpawn vTeamCity
    [15:59:35] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [15:59:36] [Server thread/INFO]: Done (2.104s)! For help, type "help" or "?"
    package com.mienka.escoreboards;

    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Main extends JavaPlugin implements Listener {
    Logger log;


    static Plugin plugin;

    public void onEnable() {
    log = Logger.getLogger("Minecraft");
    plugin = this;
    Bukkit.getServer().getPluginManager().registerEvents(this, this);


    }


    ScoreboardManager manager = Bukkit.getScoreboardManager();
    final Scoreboard board = manager.getNewScoreboard();
    final Objective objective = board.registerNewObjective("test", "dummy");


    @EventHandler
    public void PlayerJoin(PlayerJoinEvent e) {


    final Player p = e.getPlayer();


    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
    public void run() {

    ScoreboardManager manager = Bukkit.getScoreboardManager();
    final Scoreboard board = manager.getNewScoreboard();
    final Objective objective = board.registerNewObjective("test", "dummy");

    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName(ChatColor.RED + "ImagineMC");

    Score score = objective.getScore(ChatColor.AQUA + "Player name:");
    score.setScore(10);

    Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
    score1.setScore(9);

    Score score2 = objective.getScore(ChatColor.AQUA + "Health:");
    score2.setScore(7);

    long health = Math.round(p.getHealth());

    Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
    score3.setScore(6);

    p.setScoreboard(board);

    }
    },0, 20 * 10);

    }

    }
     
    #1 GekkeStef, May 24, 2016
    Last edited: May 25, 2016
  2. It says, it cannot load the Custom.jar

    [15:59:33] [Server thread/ERROR]: Could not load 'plugins\EScoreBoard - Custom.jar' in folder 'plugins'
     
    • Funny Funny x 1
  3. Nooo its not like that, EScoreBoard - Custom is 1 plugin!
     
  4. I think 'EScoreBoard - Custom' is not a valid name. Use 'EScoreBoardCustom' instead.
     
  5. Also use 'static JavaPlugin plugin' instead of 'static Plugin plugin'.
     
  6. Nope.
     
  7. May I see your plugin.yml?
     
  8. For sure!
    name: EScoreBoard
    version: 1.0
    main: com.mienka.escoreboards.Main
     
  9. I believe it's down to how you have the jar named. As said previously by @Arionas_MC said, rename the .jar to "EScoreboardCustom" or something without a hyphen(-) and space. :) It does tend to cause issues sometimes, if this doesn't work, I'll look deeper but give this a try first.
     
  10. Dosnt work!
     
  11. I figured out the issue, it was the plugin.yml!

    You had
    name:
    version:
    main:

    the correct format is
    name:
    main:
    version:

    Hope this helps! :)
     
  12. Omy gosh it it works!
     
  13. Still need to test when i get home!
     
  14. Ok what did i do wrong im just getting a error :(
     
  15.  
  16. First of all guys you don't depend on that you can't load your main class when the plugin is run on the server... This plugin is really simple what happened is that you activated a final variable out side a void. Once you assign the final that will always be the variable that you have created which in this case you have named board and objective. You see here you have 3 lines of code that are exactly the same in your class and believe it or not they contain finals... Now you can either remove the duplicate code or remove the final, I made it a bit simpler so I will give you the code but let me go into detail before you get this wrong again. Simply if you have a good look in your class these are the lines that are duplicated.

    Code (Text):
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    final Scoreboard board = manager.getNewScoreboard();
    final Objective objective = board.registerNewObjective("test", "dummy");
    The three lines on its own do not have a purpose in the class at all, they are just sitting there daydreaming waiting to be used in the class. So I would personally just remove them.

    So this is the code that will work if you have a good look you will see that I have removed the three lines below the onEnable void.

    Code (Text):
    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Main extends JavaPlugin implements Listener {
    Logger log;


    static Plugin plugin;

    public void onEnable() {
    log = Logger.getLogger("Minecraft");
    plugin = this;
    Bukkit.getServer().getPluginManager().registerEvents(this, this);


    }


    @EventHandler
    public void PlayerJoin(PlayerJoinEvent e) {


    final Player p = e.getPlayer();


    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
    public void run() {

    ScoreboardManager manager = Bukkit.getScoreboardManager();
    final Scoreboard board = manager.getNewScoreboard();
    final Objective objective = board.registerNewObjective("test", "dummy");

    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName(ChatColor.RED + "ImagineMC");

    Score score = objective.getScore(ChatColor.AQUA + "Player name:");
    score.setScore(10);

    Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
    score1.setScore(9);

    Score score2 = objective.getScore(ChatColor.AQUA + "Health:");
    score2.setScore(7);

    long health = Math.round(p.getHealth());

    Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
    score3.setScore(6);

    p.setScoreboard(board);

    }
    },0, 20 * 10);

    }

    }
    Also guys next time please read the lines of the console carefully, you can't fix an error when it has ~[?:?] in it. As you can see the line 34 had an error on it, let me show you.

    Code (Text):
    Caused by: java.lang.NullPointerException
    at com.mienka.escoreboards.Main.<init>(Main.java:34) ~[?:?]
    Thx Pixl
     
  17. Can u paste a source code in pastebin. Can u give me permission to make your plugin more functional with commands / better config and many more. Write me LS
     
  18. <3 - GekkeStef