나는 포켓몬 배틀 시뮬레이터 (기본적으로 pokemonshowdown gen1)에서 작업 중이며 포켓몬 배열을 자동화하려고하지만 스캐너 문제가 발생합니다. 파일 형식은 다음과 같습니다 : Name.Type1.Type2.hp.attack.defense.special.speed. 학습 가능한 동작 목록. 그래서 : Aerodactyl.Flying.Rock.80.105.65.60.130.Agility, Bide, Bite, Double-Edge, 두 팀, 드래곤 분노, 불의 폭발, 날아가는 길, 하이빔, 모방, 분노, 면도기 바람, 반사, 하늘 공격, 대용품, 초음속, 신속, 쓰러 뜨림, 독성, 날개 공격.파일에서 배열 채우기
저는 typeArray와 moveArray 모두에서 작동하는 메소드를 얻었지만 기본적으로 동일한 루프를 사용하여 스캐너가 파일에있는 것 대신 빈 토큰을 반환한다는 이유로 몇 가지 이유가 있습니다.
예외 :
0 Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at Controller.initPokemonArray(Controller.java:169)
at Controller.<init>(Controller.java:29)
at Driver.main(Driver.java:15)
여기 마력의에서는 parseInt 호출에서 오류를 던지고, 전체 방법입니다.
private Pokemon[] initPokemonArray() {
Pokemon[] pokemonArray = new Pokemon[83];
try {
Scanner inputScan = new Scanner(new File("src/pokemon")).useDelimiter(".");
String name = "";
Type type1 = typeArray[0];
String inputType1 = "";
Type type2 = typeArray[0];
String inputType2 = "";
int hp = 0;
int atk = 0;
int def = 0;
int spc = 0;
int spe = 0;
String[] lm = {};
Move[] learnableMoves;
int counter = 0;
while (counter < 83) {
System.out.print(counter);
if (inputScan.hasNextLine()) {
name = inputScan.next();
System.out.println(name+" ");
//System.out.print("name");
inputType1 = inputScan.next();
for (int i = 0;i < 16;i++)
if (inputType1.equals(typeArray[i].toString()))
type1 = typeArray[i];
System.out.println(type1.toString()+" ");
inputType2 = inputScan.next();
for (int i = 0;i < 16;i++)
if (inputType2.equals(typeArray[i].toString()))
type2 = typeArray[i];
System.out.println(type2.toString()+" ");
hp = Integer.parseInt(inputScan.next());
System.out.println(hp+" ");
atk = Integer.parseInt(inputScan.next());
System.out.println(atk+" ");
def = Integer.parseInt(inputScan.next());
System.out.println(def+" ");
spc = Integer.parseInt(inputScan.next());
System.out.println(spc+" ");
spe = Integer.parseInt(inputScan.next());
System.out.println(spe+" ");
lm = inputScan.next().split(",");
System.out.println();
}
//TODO move this to private helper method
learnableMoves = new Move[lm.length];
for (int i = 0;i < 160;i++) {
for (int j = 0;j < lm.length;j++) {
if (lm[j] == moveArray[i].getName())
learnableMoves[j] = moveArray[i];
}
}
pokemonArray[counter] = new Pokemon(name,type1,type2,hp,atk,def,spc,spe,learnableMoves);
counter++;
}
inputScan.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return pokemonArray;
}
면책 조항 :이 내 자바 2 코스 프로젝트이며, 또한 여기에 내 첫 번째 게시물은 그래서 나는 내가 그래서 그냥 여기로 알려져시키는하기로되어있어 정확히 알 수 없습니다.
어떤 오류가 발생합니까? – DejaVuSansMono
"hp에 대한 parseInt 호출시 오류"- 어떤 종류의 오류입니까? 모든 회선 또는 일부 회선에서 발생합니까? 이 문제를 일으키는'src/pokemon'의 일부를 포함하면 도움이 될 것입니다. – bradimus
특정 질문이 있고 당신을 위해 작성하는 다른 사람을 찾고있는 것이 아니라면 괜찮습니다. inputScan.next()를 먼저 String 변수에 저장하고 인쇄하십시오. 당신은 공간이나 뭔가를 집어 들고 있을지도 모릅니다. 또한 inputScan.nextInt()를 살펴보십시오. – Joe