我无法弄清楚这部分代码是如何抛出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)
答案 0 :(得分:2)
你的方法
public static boolean genFloor_base(World world, int i, int j, int k, String color) {
有5个参数,其中i
,j
和k
属于int
类型。
你想要使用
int.class
而不是
Integer.class
识别参数类型。