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

Solved Cannot instantiate abstract class...

Discussion in 'Development' started by Clik, Aug 20, 2019.

  1. Clik

    Clik Spider Jockey

    Messages:
    25
    GitHub:
    KadTheHunter
    So, I've been working on fixing up an outdated TurfWars plugin, and I've gotten this far and am now stuck with This error:
    Code:
    Cannot instantiate abstract class pocketmine\scheduler\Task
    The files are at https://github.com/LegoFan48737/TurfWars/tree/master/src/TurfWars

    Main.php (From the beginning to the problematic line)
    PHP:
    <?php

    namespace TurfWars;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerKickEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerDropItemEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;


    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\ProjectileLaunchEvent;
    use 
    pocketmine\event\entity\ProjectileHitEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\block\SignChangeEvent;


    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\block\Block;

    use 
    pocketmine\entity\Arrow;
    use 
    pocketmine\entity\Entity;

    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\scheduler\TaskScheduler;

    use 
    pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\nbt\tag\CompoundTag;


    use 
    pocketmine\math\Vector3;

    class 
    Main extends PluginBase implements Listener{

    public 
    $MAX 2;
    public 
    $PREFIX "§d[§9TW§d]§b ";
    public 
    $REDSPAWN;
    public 
    $BLUESPAWN;
    public 
    $config;
    public 
    $sign;

    public 
    $games = ["Game1" => ["Arena" => "TW-1""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game2" => ["Arena" => "TW-2""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game3" => ["Arena" => "TW-3""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game4" => ["Arena" => "TW-4""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game5" => ["Arena" => "TW-5""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game6" => ["Arena" => "TW-6""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game7" => ["Arena" => "TW-7""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game8" => ["Arena" => "TW-8""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game9" => ["Arena" => "TW-9""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game10" => ["Arena" => "TW-10""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0]];



    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getScheduler()->scheduleRepeatingTask(new Task($this), 20);
    Tasks.php:
    PHP:
    <?php

    namespace TurfWars;

    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;

    class 
    Tasks extends Task {

     public function 
    __construct(Main $pluginPlayer $player){
      
    $this->plugin $plugin;
         }
            public function 
    onRun($currentTick){
                
    $this->plugin->Second();
            }
    }
    Anyone know what this error is, and how to fix it? I've looked at a few other threads, but haven't found any clear solution.
     
  2. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
    when you are trying to repeat the task the plugin is repeating pocketmine\scheduler\Task instead of TrufWars\Tasks
     
  3. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
    here's the fixed code
    PHP:
    <?php

    namespace TurfWars;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerKickEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerDropItemEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;


    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\ProjectileLaunchEvent;
    use 
    pocketmine\event\entity\ProjectileHitEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\block\SignChangeEvent;


    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\block\Block;

    use 
    pocketmine\entity\Arrow;
    use 
    pocketmine\entity\Entity;

    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\scheduler\TaskScheduler;

    use 
    pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\nbt\tag\CompoundTag;


    use 
    pocketmine\math\Vector3;

    use 
    TrufWars\Tasks as GameTask;

    class 
    Main extends PluginBase implements Listener{

    public 
    $MAX 2;
    public 
    $PREFIX "§d[§9TW§d]§b ";
    public 
    $REDSPAWN;
    public 
    $BLUESPAWN;
    public 
    $config;
    public 
    $sign;

    public 
    $games = ["Game1" => ["Arena" => "TW-1""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game2" => ["Arena" => "TW-2""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game3" => ["Arena" => "TW-3""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game4" => ["Arena" => "TW-4""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game5" => ["Arena" => "TW-5""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game6" => ["Arena" => "TW-6""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game7" => ["Arena" => "TW-7""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game8" => ["Arena" => "TW-8""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game9" => ["Arena" => "TW-9""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0], "Game10" => ["Arena" => "TW-10""Status" => "JOINABLE""RedScore" => 0"BlueScore" => 0]];

    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getScheduler()->scheduleRepeatingTask(new GameTask($this), 20);
     
  4. Clik

    Clik Spider Jockey

    Messages:
    25
    GitHub:
    KadTheHunter
  5. BlueWhaleYT

    BlueWhaleYT Spider Jockey

    Messages:
    42
    GitHub:
    bluewhaleyt
    not work
     
  6. TobiasDev

    TobiasDev Spider

    Messages:
    13
    GitHub:
    tobiasg-de
    What do you mean with "not work"? You could at least describe the issue / error occuring more detailed.
     
    HimbeersaftLP likes this.
  7. BlueWhaleYT

    BlueWhaleYT Spider Jockey

    Messages:
    42
    GitHub:
    bluewhaleyt
    still gets error in console.
     
  8. BlueWhaleYT

    BlueWhaleYT Spider Jockey

    Messages:
    42
    GitHub:
    bluewhaleyt
    [Server thread/CRITICAL]: Error: "Cannot instantiate abstract class pocketmine\scheduler\Task" (EXCEPTION) in "plugins/TurfWars.phar/src/TurfWars/Main" at line 62 [13:32:02] [Server thread/DEBUG]: #0 src/pocketmine/plugin/PluginBase(120): TurfWars\Main->onEnable() [13:32:02] [Server thread/DEBUG]: #1 src/pocketmine/plugin/PluginManager(597): pocketmine\plugin\PluginBase->setEnabled(boolean 1) [13:32:02] [Server thread/DEBUG]: #2 src/pocketmine/Server(2035): pocketmine\plugin\PluginManager->enablePlugin(object TurfWars\Main) [13:32:02] [Server thread/DEBUG]: #3 src/pocketmine/Server(2019): pocketmine\Server->enablePlugin(object TurfWars\Main) [13:32:02] [Server thread/DEBUG]: #4 src/pocketmine/Server(1809): pocketmine\Server->enablePlugins(integer 1) [13:32:02] [Server thread/DEBUG]: #5 src/pocketmine/PocketMine(274): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[16] /home/container/, string[24] /home/container/plugins/) [13:32:02] [Server thread/DEBUG]: #6 src/pocketmine/PocketMine(297): pocketmine\server() [13:32:02] [Server thread/DEBUG]: #7 (1): require(string[71] phar:///home/container/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
     
  9. TobiasDev

    TobiasDev Spider

    Messages:
    13
    GitHub:
    tobiasg-de
    That's because you are creating an instance of the task class, which is the base class for all synchronous tasks and abstract, means you cannot create an instance of it.
    What you probably wanna do is create an Object of your task, which is "Tasks", not "Task".
     
  10. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
    you're calling pocketmine abstract task class to be scheduled. just change the name of the classes like what i said above already.
     
  11. BlueWhaleYT

    BlueWhaleYT Spider Jockey

    Messages:
    42
    GitHub:
    bluewhaleyt
    I followed the fix code but it still doesn't working
     
  12. TobiasDev

    TobiasDev Spider

    Messages:
    13
    GitHub:
    tobiasg-de
    Does it print out the exact same error?
     
  13. BlueWhaleYT

    BlueWhaleYT Spider Jockey

    Messages:
    42
    GitHub:
    bluewhaleyt
    yes
     
  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.