1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Error: Call to a member of function on null

Discussion in 'Facepalm' started by ethaniccc, Mar 15, 2020.

  1. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    I don't know how to fix this, so I came here (yes I'm a big noob lol).
    So this is the error:
    Code:
    2020-03-15 [20:25:34] [Server thread/CRITICAL]: Error: "Call to a member function banPlayerCombatHacks() on null" (EXCEPTION) in "plugins/StaffMode/src/ethaniccc/StaffMode/BanMenu" at line 40
    This is my code in BanMenu.php:
    PHP:
    <?php

    namespace ethaniccc\StaffMode;

    use 
    muqsit\invmenu\InvMenu;

    use 
    pocketmine\inventory\transaction\action\SlotChangeAction;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\ClosureTask;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Server;

    class 
    BanMenu{

        private 
    $plugin;
        
        public function 
    _construct(StaffMode $plugin){
            
    $this->plugin $plugin;
        }
        
        public function 
    openBanMenu(Player $senderPlayer $who) : void{
            
    $menu InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST);
            
    $menu->readonly();
            
    $menu->setName(TextFormat::RED $who->getName() . "'s profile");
            for(
    $i 0$i <= 53; ++$i) {
               
    $menu->getInventory()->setItem($iItem::get(Item::STAINED_GLASS_PANE01)->setCustomName(TextFormat::RESET " "));
               }
            
    $menu->getInventory()->setItem(20Item::get(27601)->setCustomName(TextFormat::BOLD TextFormat::RED "Combat Hacks"));
            
    $menu->setListener(function(Player $playerItem $itemClickedItem $itemClickedWithSlotChangeAction $action) use ($who$menu) : bool{
                switch (
    $itemClicked->getId()) {
                    case 
    Item::DIAMOND_SWORD:
                        
    $player->removeWindow($action->getInventory());
                        
    $this->plugin->banPlayerCombatHacks($who); //line of error
                        
    return false;
                        break;
                }
            });
            
    $menu->send($sender);
        }
    }
    Can anyone help me?
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    That means that $this->plugin is null, there is probably something wrong in the part of your code where you create the BanMenu object. (new Banmenu())
     
  3. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    I fixed it by making it so that instead of my BanMenu class into going back into the main class and using a function from there, I just used the code from the function and put it in there, now it doesn't appear.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.