我在这里有两个类,我试图链接在一起,但无法使其工作。一个叫smokers
,一个叫Pair
。将两个类连接在一起
我的编译器正在喷出错误,说它找不到符号pair
。
我已将它们放在同一个包中。不知道为什么它没有注册它。
package smokerz;
import java.util.*;
public class smokers{
//initialise
//create a node inner class which has the nodes position
//make 2D array of nodes
//
public static void main(String[]args){
initialise();
}
public static void initialise(){
List<Pair<Integer, Integer>> pairedCoordinates = new ArrayList<Pair<Integer, Integer>>();
Scanner scan = new Scanner(System.in);
int line = 0;
//for board boundaries
int boardX;
int boardY;
while (scan.hasNextLine()){
//means we're reading the board coordinates
if (line == 0){
boardX = scan.nextInt();
boardY = scan.nextInt();
}
int nonSmokersPosX;
int nonSmokersPosY;
nonSmokersPosX = scan.nextInt();
nonSmokersPosY = scan.nextInt();
pairedCoordinates.add(new Pair(nonSmokersPosX, nonSmokersPosY));
line++;
}
package smokerz;
public class Pair<X, Y>{
private X xcoord;
private Y ycoord;
public Pair(X xcoord, Y ycoord){
this.xcoord = xcoord;
this.ycoord = ycoord;
}
public X getXCoord(){
return xcoord;
}
public Y getYCoord(){
return ycoord;
}
public void setXCoord(X x){
this.xcoord = x;
}
public void setYCoord(Y y){
this.ycoord = y;
}
}
请发布您的堆栈跟踪。使用诸如“链接”之类的术语听起来就像是在使用C++(嗯......过去的美好时光)。 –
smokers.java:19:找不到符号 符号:类对 位置:类smokerz.smokers \t \t列表<配对<整数,整数>> pairedCoordinates =新的ArrayList <配对<整数,整数>>(); \t \t^ 吸烟者。java:19:找不到符号 symbol:class Pair location:class smokerz.smokers \t \t List> pairedCoordinates = new ArrayList >(); \t \t^ smokers.java:36:找不到符号 符号:类对 位置:类smokerz.smokers \t pairedCoordinates.add(双新(nonSmokersPosX,nonSmokersPosY)); –
我想在我的吸烟班里创建我的配对班的一个实例。 –