0
OpenGL에 OBJ 모델을로드하려고합니다.java.lang.NumberFormatException : 빈 문자열 - OBJ 모델 로더
public class OBJLoader {
public static Model loadModel(File f) throws FileNotFoundException, IOException {
BufferedReader reader = new BufferedReader(new FileReader(f));
Model m = new Model();
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith("v ")) {
float x = Float.valueOf(line.split(" ")[1]); //Error is here
float y = Float.valueOf(line.split(" ")[2]);
float z = Float.valueOf(line.split(" ")[3]);
m.vertices.add(new Vector3f(x,y,z));
} else if (line.startsWith("vn ")) {
float x = Float.valueOf(line.split(" ")[1]);
float y = Float.valueOf(line.split(" ")[2]);
float z = Float.valueOf(line.split(" ")[3]);
m.normals.add(new Vector3f(x,y,z));
} else if (line.startsWith("f ")) {
Vector3f vertexIndices = new Vector3f(
Float.valueOf(line.split(" ")[1].split("/")[0]),
Float.valueOf(line.split(" ")[2].split("/")[0]),
Float.valueOf(line.split(" ")[3].split("/")[0])
);
Vector3f normalIndices = new Vector3f(
Float.valueOf(line.split(" ")[1].split("/")[2]),
Float.valueOf(line.split(" ")[2].split("/")[2]),
Float.valueOf(line.split(" ")[3].split("/")[2])
);
m.faces.add(new Face(vertexIndices, normalIndices));
}
}
reader.close();
return m;
}
}
사람이 말할 수 :
Exception in thread "main" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1011)
at java.lang.Float.valueOf(Float.java:417)
at game.trippylizard.OBJLoader.loadModel(OBJLoader.java:18)
at game.trippylizard.MainScreen.<init>(MainScreen.java:39)
at game.trippylizard.MainScreen.main(MainScreen.java:71)
이 내 OBJLoader 클래스의 코드입니다 : 내가 파일을 읽을 때 나는 모델에 대한 데이터를 점점 문제가 있습니다, 나는이 오류 어떻게이 문제를 해결할 수 있습니까?
P. 나는 정규 표현식과 그 종류의 서식에 대해 좀 새로운 것이다.
이 입력 샘플을 제공하십시오. 입력 한 내용이 유효하지 않거나 잘못 파싱 된 것 같습니다. – ChristopherS
OBJLoader 클래스의 코드에서 18 번째 줄을 가리 키십시오. –