简体   繁体   English

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

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

I cannot figure out how this part of code always throws NoSuchMethodException. 我无法弄清楚这部分代码如何总是抛出NoSuchMethodException。 Can anyone help? 有人可以帮忙吗? The Method M... line is probably where the code is erring. 方法M ...行可能是代码出错的地方。 Either the method getMethod is broken or I am using it wrong. 方法getMethod损坏了,或者我使用了错误的方法。 If you need more of the file just ask. 如果您需要更多文件,请询问。 Thanks! 谢谢!

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);
    }

and here is the method: 这是方法:

 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;
}

(And yes this is a Minecraft mod) (是的,这是Minecraft mod)

Your method 你的方法

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

has 5 parameters, where i , j , and k , are of type int . 有5个参数,其中ijk的类型为int

You'll want to use 您将要使用

int.class

instead of 代替

Integer.class

to identify the parameter type. 识别参数类型。

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

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