Search code examples
javaimportlwjgl

Java not using Import


Even though I have the library imported Java doesn't recognize the function. If I call the function over the library directly it's working fine.

Like that it's not working:

import org.lwjgl.stb.STBImage;

ByteBuffer data = stbi_load(filename, width, height, comp, 4);

That just works fine:

ByteBuffer data = org.lwjgl.stb.STBImage.stbi_load(filename, width, height, comp, 4);

Solution

  • You are importing a class, so you should refer to the method via its class:

    ByteBuffer data = STBImage.stbi_load(filename, width, height, comp, 4);
    

    Alternatively, if you want to call the method without the class name, you should statically import the method:

    import static org.lwjgl.stb.STBImage.stbi_load;
    

    And, of course, you could use a wildcard:

    import static org.lwjgl.stb.STBImage.*;