繁体   English   中英

class.getMethod()在我的上下文中不起作用

[英]class.getMethod() is not working in my context

我无法弄清楚这部分代码如何总是抛出NoSuchMethodException。 有人可以帮忙吗? 方法M ...行可能是代码出错的地方。 方法getMethod损坏了,或者我使用了错误的方法。 如果您需要更多文件,请询问。 谢谢!

floorName = "Base";
try {
        Class[] cArg = new Class[5];
        cArg[0] = World.class;
        cArg[1] = Integer.class;
        cArg[2] = Integer.class;
        cArg[3] = Integer.class;
        cArg[4] = String.class;
        Method m = TowerFloors.class.getMethod("genFloor_" + floorName.toLowerCase(), cArg); //Probable Origin of Throwable Error
        try {
            done = (Boolean) m.invoke(m, x, y, z, color);
            success = done;
        } catch (Exception e) {
            DungeonMod.logger.log(Level.ERROR, "Error in generating tower floor \"" + floorName + "\"(" + e + "), generating \"Base\" floor instead.");
            done = genFloor_base(worldA, x, y, z, color);
        }
    } catch (Exception e) {
        DungeonMod.logger.log(Level.ERROR, "Error in generating tower floor \"" + floorName + "\"(" + e + "), generating \"Base\" floor instead.");
        done = genFloor_base(worldA, x, y, z, color);
    }

这是方法:

 public static boolean genFloor_base(World world, int i, int j, int k, String color) {
    if (color.toLowerCase().equals("blue")) {
        //Floor
        BlockFill.fillRectangle(world, i - 10, j, k - 10, i + 10, j, k + 10, TowerDungeonBuildingBlocks.towerDungeonWallBlue);
        //Roof
        BlockFill.fillRectangle(world, i - 10, j + 5, k - 10, i + 10, j + 5, k + 10, TowerDungeonBuildingBlocks.towerDungeonWallBlue);
        //++Wall
        BlockFill.fillRectangle(world, i + 10, j + 1, k + 10, i + 10, j + 4, k - 10, TowerDungeonBuildingBlocks.towerDungeonWallBlue);
        //--Wall
        BlockFill.fillRectangle(world, i - 10, j + 1, k - 10, i - 10, j + 4, k + 10, TowerDungeonBuildingBlocks.towerDungeonWallBlue);
        //+-Wall
        BlockFill.fillRectangle(world, i + 10, j + 1, k - 10, i - 10, j + 4, k - 10, TowerDungeonBuildingBlocks.towerDungeonWallBlue);
        //-+Wall
        BlockFill.fillRectangle(world, i - 10, j + 1, k + 10, i + 10, j + 4, k + 10, TowerDungeonBuildingBlocks.towerDungeonWallBlue);
        return true;
    }
    return false;
}

(是的,这是Minecraft mod)

你的方法

public static boolean genFloor_base(World world, int i, int j, int k, String color) {

有5个参数,其中ijk的类型为int

您将要使用

int.class

代替

Integer.class

识别参数类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM