안녕하십니까, 쉬운 오후가 있습니다. 임 try-catch 루프 내부에서 배열의 내용을 가져 와서 루프 외부에 선언 된 배열 안에 배치하는 데 문제가 있습니다. 이 작업을 수행하려는 이유는 외부의 주 기능에서 호출 할 수 있기 때문입니다. 어떤 포인터? try-catch 루프 내부에서 배열 가져 오기
내 코드를 살펴 유무 : 나는 배열 votesPerPosition []의 내용을 얻을 ArrayVotesPosition [] 안에 넣어하려고을;
모든 포인터? 감사! 귀하의 도움을 많이 주시면 감사하겠습니다.
public class Vote{
int voter = 0;
Scanner sc;
BufferedReader br;
String line;
FileInputStream fis;
public int j = 0;
private int voterCount = 0;
public Arrays VotesPosition[];
public Vote() {
sc = new Scanner(System.in);
System.out.println("Enter file name > ");
String filename = sc.next();
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
} catch (FileNotFoundException ex) {
//Logger.getLogger(Vote.class.getName()).log(Level.SEVERE, null, ex);
}
do{
voter++;
try {
filename = br.readLine();
} catch (IOException ex) {
Logger.getLogger(Vote.class.getName()).log(Level.SEVERE, null, ex);
}
String votesPerPosition[] = filename.split(",");
for(String vote: votesPerPosition){
Integer.parseInt(vote);
for (j = 0; j < votesPerPosition.length; j++);{
System.out.println("voter " + voter + "voted for candidate #" + vote);
voterCount++;
}
}
return String votesPerPosition; //<-------------- This is what I am trying//
}while(filename != null);
}
/**
* @return the voterCount
*/
public int getVoterCount() {
return voterCount;
}
/**
* @param voterCount the voterCount to set
*/
public void setVoterCount(int voterCount) {
this.voterCount = voterCount;
}
/**
* @return the VotesPosition
*/
public Arrays[] getVotesPosition() {
return VotesPosition;
}
/**
* @param VotesPosition the VotesPosition to set
*/
public void setVotesPosition(Arrays[] VotesPosition) {
this.VotesPosition = VotesPosition;
}
}
입력 해 주셔서 감사합니다.하지만 여전히 줄 반환 오류에 대한 오류를 표시합니다. votesPerPosition; 클래스를 public으로 변경 한 후에도 String [] Vote() 오류가 진술이 아님을 나타냅니다. – SandyBites
사과드립니다. 나는 대답 한 나의 대답에 오류가 있었다. 'return votesPerPosition;'이어야합니다. – Bathsheba