0
votes

I would like to add texture to my model but I keep getting this error . Any help would be appreciated. Thanks

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: Unable to start activity ComponentInfo{com.app.glapp/com.app.glapp.MainActivity}: java.lang.NumberFormatException: Invalid int: ""
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
    at android.app.ActivityThread.access$900(ActivityThread.java:175)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5603)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: ""
    at java.lang.Integer.invalidInt(Integer.java:137)
    at java.lang.Integer.parseInt(Integer.java:358)
    at java.lang.Integer.parseInt(Integer.java:331)
    at com.mingatronenterprices.glapp.mesh.(mesh.java:72)
    at com.mingatronenterprices.glapp.ClearRenderer.(MainActivity.java:70)
    at com.app.glapp.ClearGLSurfaceView.(MainActivity.java:54)
    at com.app.glapp.MainActivity.onCreate(MainActivity.java:32)
    at android.app.Activity.performCreate(Activity.java:5458)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
    at android.app.ActivityThread.access$900(ActivityThread.java:175)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5603)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)

1
Well clearly the elements of your faceComponent or vertexCompo or textureComp arrays can't be parsed as integers / floats. Use a debugger and fix your split pattern.Mena
Please add the exception (+stacktrace) to your question text. And make sure that your j String doesn't look like [number]//[number] (e.g. 1//2). You can't use a double slash (or more) with your current code.Tom
Tom, actually I think it could look like this. How do I change it? I'm new to all these split methods. Thanks for replying!limus
@limus trysplit("/+") instead of split("/").Tom
@Tom Thank you! I had to make a couple other changes but this did the trick!limus

1 Answers

0
votes

Try to modify like this:

       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) {
            }
        }