Error java.lang.NullPointerException: null

Discussion in 'Plugin Development' started by nyanneko0113, Aug 8, 2020.

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

    nyanneko0113

    (I can't speak English, I am Japanese)


    Error:
    [17:34:11 ERROR]: Error occurred while enabling Hide_And_Seek v0.0.1 (Is it up to date?)
    java.lang.NullPointerException: null
    at nyanneko.hide_and_seek.api.ScoreBoardAPI.CreateScoreBoard(ScoreBoardAPI.java:29) ~[?:?]
    at nyanneko.hide_and_seek.Main.onEnable(Main.java:21) ~[?:?]

    Error Code:
    (sub)
    Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();;
    Objective game = board.getObjective("Hide_And_Seek");
    Objective timer = board.getObjective("Timer");
    --
    game.getScore(ChatColor.YELLOW + " ").setScore(14);

    (Main)
    @Override
    public void onEnable() {
    getCommand("start").setExecutor(new StartEndCommand());
    getCommand("end").setExecutor(new StartEndCommand());
    getCommand("spawnset").setExecutor(new SpawnSetCommand(this));
    new ScoreBoardAPI().CreateScoreBoard();
    }
     
  2. Offline

    KarimAKL

    @nyanneko0113 What is line 29 of ScoreBoardAPI? I'm guessing it's:
    Code:Java
    1. game.getScore(ChatColor.YELLOW + " ").setScore(14);

    which would mean that the Objective "game" is null.
     
  3. Offline

    nyanneko0113

    (game)
    Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();;
    Objective game = board.getObjective("Hide_And_Seek");

    Please tell me how to fix!!

    ALL Code

    Scoreboard :
    Code:
    public class ScoreBoardAPI {
      
        Scoreboard board =  Bukkit.getScoreboardManager().getNewScoreboard();;
        Objective game = board.getObjective("Hide_And_Seek");
        Objective timer = board.getObjective("Timer");
    
        Team oni = board.getTeam("oni");
        Team player = board.getTeam("player");
    
        public void CreateScoreBoard() {
            //スコアボード作成
           board.registerNewObjective("Hide_And_Seek", "dummy");
           board.registerNewObjective("Timer", "dummy");
    
           //チーム作成
            board.registerNewTeam("oni");
            board.registerNewTeam("player");
    
            //スコアボード(ゲーム)設定
            game.getScore(ChatColor.YELLOW + "残り時間").setScore(14);
            game.getScore("").setScore(13);
            game.getScore(ChatColor.AQUA + "プレイヤー人数").setScore(12);
            game.getScore(ChatColor.RED + "鬼:").setScore(9);
            game.getScore(ChatColor.GOLD + "プレイヤー:").setScore(8);
    
            //スコアボード(タイマー)設定
            timer.getScore("counttime").setScore(10);
            timer.getScore("gametime").setScore(300);
        }
    
        public void RemoveScoreBoard() {
            oni.unregister();
            player.unregister();
            game.unregister();
            timer.unregister();
        }
    }
    Main:
    Code:
    public class Main extends JavaPlugin {
    
        public Main() {
            FileConfiguration config = getConfig();
        }
    
        @Override
        public void onEnable() {
            getCommand("start").setExecutor(new StartEndCommand());
            getCommand("end").setExecutor(new StartEndCommand());
            getCommand("spawnset").setExecutor(new SpawnSetCommand(this));
            new ScoreBoardAPI().CreateScoreBoard();
        }
    
        @Override
        public void onDisable() {
            new ScoreBoardAPI().RemoveScoreBoard();
        }
    
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 8, 2020
  4. Offline

    KarimAKL

    @nyanneko0113 You have to add a null check to the objective.
     
  5. Offline

    nyanneko0113

    Error:

    [20:53:12 ERROR]: Error occurred while disabling Hide_And_Seek v0.0.1 (Is it up to date?)
    java.lang.NullPointerException: null
    at nyanneko.hide_and_seek.api.ScoreBoardAPI.RemoveScoreBoard(ScoreBoardAPI.java:41) ~[?:?]
    at nyanneko.hide_and_seek.Main.onDisable(Main.java:26) ~[?:?]

    create , remove error why..

    null check is conditional jump?

    I don't know so please teach me...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 8, 2020
  6. Offline

    KarimAKL

    @nyanneko0113 A null check:
    Code:Java
    1. Objective game = ...;
    2. if (game != null) {
    3. // Use 'game'
    4. }
     
  7. Offline

    nyanneko0113

    not error , not work....


    Code:
    >rl
    [13:33:58 INFO]: CONSOLE: Please note that this command is not supported and may cause issues when using some plugins.
    [13:33:58 INFO]: CONSOLE: If you encounter any issues please use the /stop command to restart your server.
    [13:33:58 INFO]: Debug logging is disabled
    
    ~~~~~
    
    [13:33:58 INFO]: [Hide_And_Seek] Disabling Hide_And_Seek v0.0.1
    [13:33:59 INFO]: [Hide_And_Seek] Loading Hide_And_Seek v0.0.1
    [13:33:59 INFO]: [ViaVersion] Loading ViaVersion v3.0.1
    [13:33:59 INFO]: [ViaVersion] ViaVersion 3.0.1 is now loaded, injecting!
    [13:33:59 ERROR]: [ViaVersion] ViaVersion is already loaded, this should work fine. If you get any console errors, try rebooting.
    [13:33:59 INFO]: [ViaVersion] Loading 1.12.2 -> 1.13 mappings...
    [13:33:59 INFO]: [ViaVersion] Loading 1.13.2 -> 1.14 mappings...
    [13:33:59 INFO]: [ViaVersion] Loading 1.14.4 -> 1.15 mappings...
    [13:33:59 INFO]: [Nyanneko_Ban_Plugin] Loading Nyanneko_Ban_Plugin v0.0.1
    [13:33:59 INFO]: [Hide_And_Seek] Enabling Hide_And_Seek v0.0.1
    ~~~~~~

    >scoreboard objectives list
    [13:35:43 INFO]: There are no objectives on the scoreboard
    >scoreboard teams list
    [13:35:48 INFO]: There are no teams registered on the scoreboard
    >
     
  8. Offline

    timtower Moderator Moderator

    Locked
    Protocol hacks are not supported by Bukkit
     
Thread Status:
Not open for further replies.

Share This Page