我在這裏有兩個類,我試圖鏈接在一起,但無法使其工作。一個叫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)); –
我想在我的吸菸班裏創建我的配對班的一個實例。 –