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

Solved Cannot instantiate abstract class while unserialize in Config?

Discussion in 'Development' started by instantlyta, Dec 22, 2017.

  1. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    Code:
    [Server thread/CRITICAL]: Error: "Cannot instantiate abstract class pocketmine\item\Food" (EXCEPTION) in "src/pocketmine/utils/Config" at line 158
    Because I tried to save a Food-inheritance to the config, I guessed?
    Don't know how to fix this. Can you help me?
    I'm using Config::SERIALIZED
     
  2. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
    Code?
     
  3. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Can you show your code to save data?
     
  5. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    PHP:
    $contents $inventory->getContents();
    $data = new Config(self::getInstance()->getDataFolder() . "data.sl"Config::SERIALIZED);
            
    $data->set($player->getLowerCaseName(), $contents);
            
    $data->save();
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    can you just show us the whole code?
    we dont have time to ask for all the details one by one
     
  7. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    What do you want? Do you know what I am asking about?
     
  8. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    Fine I give you full latest 1.2 plugin for this topic.
     
  9. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
  10. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    What I suspect is that you've been using an older version of PMMP, then updated it and this error occured. That's probably because there've been many food changes/refactors in the last couple days.
     
    instantlyta and EdwardHamHam like this.
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It seems that you are directly serializing objects in the PocketMine API. This may be unsafe, as it relies on the non-API part of the objects, such as private properties. These are subject to change without notice. Consider using another format rather than serializing everything.
    In addition, serializing of a class not completely controlled by you may lead to serialization of undesired values, such as references to god objects (e.g. Server). As the PocketMine API does not guarantee the serialization safety, direct serialization should be avoided.
     
    instantlyta likes this.
  12. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
  13. instantlyta

    instantlyta Slime

    Messages:
    96
    GitHub:
    intagaming
    It is basically config.yml with the type of Config::SERIALIZED instead of Config::YAML

    FIX: Quick fix for this, example included, Windows only. But not preserve the item though.
    https://drive.google.com/open?id=1jxI0dM2VEZTGS5MW7Z2f4egVqZvIn_0y

    Place data.sl into the directory, run fixfood.cmd, output the newdata.sl that had been removed all pocketmine\item\Food items
     
  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.