类型 xxx 中的方法 xxx 不适用于 arguments()
The method xxx in the type xxx is not applicable for arguments()
我是 java 的新手,我正在尝试用建筑 class 和城市 class 做一个城市规划项目。尝试在 city class 中构建 addStructure 方法时出现错误“Building 类型中的方法 isValidPlacement 不适用于 arguments()”,其中 returns true or false based on the condition in来自建筑物 class 的方法 isValidPlacement。而且我不确定为什么以及如何修复它。
public boolean addStructure(int x, int y, Building structure) {
// x & y are new postions
// Structure is a building object called from building constructor
int posx = x;
int posy = y;
int w = structure.getWidth();//Building width
int l = structure.getLength();//Building length
int layw = layout[0].length;// City width (Building type 2d array Building[][] layout
int layl = layout.length;// City length
String sign = structure.toString();
if (Building.isValidPlacement() == false) { // Error: The method isValidPlacement in the type Building is not applicable for arguments()
return false;
} else {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
layout[i][j] = new Building(sign,x,y);
}
}
}
}
IsValidPlacement 方法检查两个条件:建筑物是否在城市范围内以及建筑物是否与现有建筑物重叠。
public boolean isValidPlacement(Building[][] layout,int x, int y) { //example 2x2
//x and y are position of the building where we wish to plant
// call for the get width function to compare
int w = getWidth();
int l = getLength();
int layw = layout[0].length;
int layl = layout.length;
//step 1 check for within city
if (x<0 || x+w > layw) { // check if x is outside of range
return false;
} else if (y < 0 || y+l > layl) { //Check if y is outside of range
return false;
} // If the above cond. all passed then check if overlap.
for (int i = x; i < x+w ; ) {
for (int j = y; j < y+l;) {
if (layout[i][j] != null) {
return false;}
}
} return true;
}
两个函数都应该return判断真假。
这一行-
if (Building.isValidPlacement() == false) {
// Error: The method isValidPlacement in the type Building is
not applicable for arguments()
return false;
}
- 尽管 isValidPlacement 方法包含参数,但调用时没有参数。传入指定参数修复错误
我是 java 的新手,我正在尝试用建筑 class 和城市 class 做一个城市规划项目。尝试在 city class 中构建 addStructure 方法时出现错误“Building 类型中的方法 isValidPlacement 不适用于 arguments()”,其中 returns true or false based on the condition in来自建筑物 class 的方法 isValidPlacement。而且我不确定为什么以及如何修复它。
public boolean addStructure(int x, int y, Building structure) {
// x & y are new postions
// Structure is a building object called from building constructor
int posx = x;
int posy = y;
int w = structure.getWidth();//Building width
int l = structure.getLength();//Building length
int layw = layout[0].length;// City width (Building type 2d array Building[][] layout
int layl = layout.length;// City length
String sign = structure.toString();
if (Building.isValidPlacement() == false) { // Error: The method isValidPlacement in the type Building is not applicable for arguments()
return false;
} else {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
layout[i][j] = new Building(sign,x,y);
}
}
}
}
IsValidPlacement 方法检查两个条件:建筑物是否在城市范围内以及建筑物是否与现有建筑物重叠。
public boolean isValidPlacement(Building[][] layout,int x, int y) { //example 2x2
//x and y are position of the building where we wish to plant
// call for the get width function to compare
int w = getWidth();
int l = getLength();
int layw = layout[0].length;
int layl = layout.length;
//step 1 check for within city
if (x<0 || x+w > layw) { // check if x is outside of range
return false;
} else if (y < 0 || y+l > layl) { //Check if y is outside of range
return false;
} // If the above cond. all passed then check if overlap.
for (int i = x; i < x+w ; ) {
for (int j = y; j < y+l;) {
if (layout[i][j] != null) {
return false;}
}
} return true;
}
两个函数都应该return判断真假。
这一行-
if (Building.isValidPlacement() == false) {
// Error: The method isValidPlacement in the type Building is
not applicable for arguments()
return false;
}
- 尽管 isValidPlacement 方法包含参数,但调用时没有参数。传入指定参数修复错误