java.lang.NumberFormatException:无效的int:“”模型纹理

时间:2015-11-04 17:18:24

标签: java android opengl-es

我想为我的模型添加纹理但是我一直收到这个错误。任何帮助,将不胜感激。谢谢

for (String i : faces) {
    for (String j : i.split(" ")) {
        iCoords[faceIndex] = (short) faceIndex++;
        String[] faceComponent = j.split("/");

        String vertex = vertexes.get(Integer.parseInt(faceComponent[0]) - 1);

        // this line throws NFE
        String texture = textures.get(Integer.parseInt(faceComponent[1]) - 1);
        String vertexComp[] = vertex.split(" ");
        String textureComp[] = texture.split(" ");

        for (String v : vertexComp) {
            vCoords[vertexIndex++] = Float.parseFloat(v);
        }

        for (String t : textureComp) {
            tCoords[textureIndex++] = Float.parseFloat(t);
        }
    }
}
  

java.lang.RuntimeException:无法启动活动   ComponentInfo {com.app.glapp / com.app.glapp.MainActivity}:   java.lang.NumberFormatException:无效的int:“”
  在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
  在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
  在android.app.ActivityThread.access $ 900(ActivityThread.java:175)
  在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1308)
  在android.os.Handler.dispatchMessage(Handler.java:102)
  在android.os.Looper.loop(Looper.java:146)
  在android.app.ActivityThread.main(ActivityThread.java:5603)
  at java.lang.reflect.Method.invokeNative(Native Method)
  在java.lang.reflect.Method.invoke(Method.java:515)
  在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1283)
  在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
  at dalvik.system.NativeStart.main(Native Method)
  引起:java.lang.NumberFormatException:无效的int:“”
  在java.lang.Integer.invalidInt(Integer.java:137)
  在java.lang.Integer.parseInt(Integer.java:358)
  在java.lang.Integer.parseInt(Integer.java:331)
  在com.mingatronenterprices.glapp.mesh。(mesh.java:72)
  在com.mingatronenterprices.glapp.ClearRenderer。(MainActivity.java:70)
  在com.app.glapp.ClearGLSurfaceView。(MainActivity.java:54)
  在com.app.glapp.MainActivity.onCreate(MainActivity.java:32)
  在android.app.Activity.performCreate(Activity.java:5458)
  在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
  在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
  在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
  在android.app.ActivityThread.access $ 900(ActivityThread.java:175)
  在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1308)
  在android.os.Handler.dispatchMessage(Handler.java:102)
  在android.os.Looper.loop(Looper.java:146)
  在android.app.ActivityThread.main(ActivityThread.java:5603)
  at java.lang.reflect.Method.invokeNative(Native Method)
  在java.lang.reflect.Method.invoke(Method.java:515)
  在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1283)
  在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
  在dalvik.system.NativeStart.main(本地方法)

1 个答案:

答案 0 :(得分:0)

尝试修改如下:

       for (String v : vertexComp) {
            try {
                vCoords[vertexIndex++] = Float.parseFloat(v);
            }
            catch (NumberFormatException e) {
            }
        }

        for (String t : textureComp) {
            try {
                tCoords[textureIndex++] = Float.parseFloat(t);
            }
            catch (NumberFormatException e) {
            }
        }