Help please, I'm new to Java. I took buildcraft 7.1 as the basis, deciding to make my auto-stack, but for some reason when I start with buildsoft's Tile, everything works and the GUI opens, but if I copy its Tile from the source and connect it, then a casting error occurs, I, in fact, did not change anything, but only used it a little differently, because TileEntity returns and it is the "parent" of TileBuildCraft, I thought the parent class should be brought to the child without any questions, "why cheers" why? Already tried everything, nothing helps ...

Caused by: java.lang.ClassCastException: buildcraft.factory.TileAutoWorkbench cannot be cast to com.silvercraft.tile_entity.TileAutoWorkbench at com.silvercraft.handler.SCGuiHandler.getServerGuiElement(SCGuiHandler.java:36) ~[SCGuiHandler.class:?] 

TileBuildCraft: http://paste.ubuntu.com/23203777/

TileAutoWorkbench: http://paste.ubuntu.com/23203781/

IGuiHandler: http://paste.ubuntu.com/23203795/

ContainerAutoWorkbench: http://paste.ubuntu.com/23203804/

Log: http://paste.ubuntu.com/23203829/

    1 answer 1

    parent class should be reduced to a child without questions "with a bang"

    Not. A child class can always be reduced to the parent, but not vice versa. Example:

      class A{ void funcA(){ //do smth A } } class B extends A{ void funcB(){ //do smth B } } class Main{ public static void main(String[] args){ A aa = new A(); A ab = new B(); B bb = new B(); aa.funcA(); // - выполнится bb.funcB(); // - тоже выполнится ab.funcB(); // - выдаст ошибку, потому что в классе А не //задекларирован метод funcB(); } } 
    • Yes, I messed up when I wrote at night, the child to the parent and not vice versa, because the parent and child entities are included, and the parent child is far from a fact, the child TileAutoWorkbench is from TileBuildCraft and is inherited from TileEntity, respectively, I just run an error at the work stage and not code checks, in that and complexity. But thanks anyway for the answer. - garaphone