0

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)

6
  • 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. Commented Nov 4, 2015 at 17:20
  • 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. Commented Nov 4, 2015 at 17:20
  • 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! Commented Nov 4, 2015 at 17:50
  • @limus trysplit("/+") instead of split("/"). Commented Nov 4, 2015 at 17:52
  • @Tom Thank you! I had to make a couple other changes but this did the trick! Commented Nov 4, 2015 at 18:24

1 Answer 1

0

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) {
            }
        }
Sign up to request clarification or add additional context in comments.

2 Comments

I'm afraid it's not the case. Exception is thrown on the "String texture...." line
And it is not a good idea to ignore that exception, because it looks like a programming mistake here, not like an "expected exception".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.