NoteBlockAPI NullPointerException

Discussion in 'Plugin Development' started by Chr0mosom3, Sep 1, 2019.

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

    Chr0mosom3

    Dear alive people,

    I am making a plugin, which has a custom entity named bechdoldt, now I have a problem, whenever I use the bechdoldt variable, it throws a nullpointer exception, for example when I check if it is null
    Code:
    boolean hmm = Bechdoldt == null;
    main.getLogger().info(Boolean.toString(hmm));
    or when I am using the api and I am using the entity to play music
    Code:
    esp.setEntity(Bechdoldt);
    or when I try to get the location and use it for the api
    Code:
    esp.setTargetLocation(Bechdoldt.getLocation());

    help?

    full code
    Code:
    public Plugin plugin;
        public Main main;
        public WitherSkeleton Bechdoldt;
        public BossBar bar;
        public String name = ChatColor.translateAlternateColorCodes('§', "§f[§cDICTATOR§f] §9Bechdoldt");
        public int task;
        public EntitySongPlayer esp;
       
       
        public MsBechdoldt(Location arg0, Plugin arg1, Main arg2) {
            summonBechdoldt(arg0);
            plugin = arg1;
            main = arg2;
           
            esp = new EntitySongPlayer(main.getBechdoldtMusic());
        }
       
       
        public void summonBechdoldt(Location loc) {
            Bechdoldt = (WitherSkeleton) loc.getWorld().spawnEntity(loc, EntityType.WITHER_SKELETON);
            bar = Bukkit.createBossBar("§f[§cDICTATOR§f] §9Bechdoldt", BarColor.PURPLE, BarStyle.SEGMENTED_20);
            Bechdoldt.setCanPickupItems(false);
            Bechdoldt.setCustomName(name);
            Bechdoldt.setCustomNameVisible(true);
            Bechdoldt.setMaxHealth(100);
            Bechdoldt.setHealth(100);
            boolean hmm = Bechdoldt == null;
            main.getLogger().info(Boolean.toString(hmm));
            esp.setEntity(Bechdoldt);
            esp.setDistance(100);
            for (Player p : Bukkit.getOnlinePlayers()) {
                esp.addPlayer(p);
            }
            esp.setPlaying(true);
        }
     
  2. Online

    KarimAKL

    @MrDaniel Checking if the variable is null shouldn't throw an exception. Try checking if it's null before using any of it's methods, and then remember to return if it's null.
     
  3. Offline

    Chr0mosom3

    Ok, I did that, but now it's saying that there is a nullpointerexception on this line of code:

    Code:
    esp.setEntity(Bechdoldt);
     
  4. Online

    KarimAKL

    @MrDaniel Did you do something like this?
    Code:Java
    1. if (esp == null) System.out.println("esp is null");
    2. if (Bechdoldt == null) System.out.println("Bechdoldt is null");
    3. return;

    And what was the result?
     
Thread Status:
Not open for further replies.

Share This Page