为什么FileInputStream不起作用?

时间:2015-03-22 18:22:59

标签: java textures lwjgl texture2d

我尝试加载纹理,当我使用此代码时:

int id = TextureLoader.getTexture(ext, new FileInputStream(new File("./resources/textures/" + fileName)));

红色下划线,错误是:

not suitable method found for getTexture(String,FileInputStream)
method TextureLoader.getTexture(String) is not applicable
(actual and formal argument lists differ in length)
not suitable method found for getTexture(String,int,int,int,int) is not applicable
(actual and formal argument lists differ in length)

并且有方法:

public static Texture loadTexture(String fileName)
    {
        String[] splitArray = fileName.split("\\.");
        String ext = splitArray[splitArray.length - 1];


        try
        {

           int id = TextureLoader.getTexture(ext, new FileInputStream(new File("./resorces/textures/" + fileName)));

        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }

        return null;
    }

这是我第一次尝试加载纹理。 那么这个方法或代码有什么问题呢?

1 个答案:

答案 0 :(得分:0)

TextureLoader.getTexture()返回一个Texture对象,而不是一个int。

还要确保您拥有正确的导入:

import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

请参阅本教程中的示例:http://wiki.lwjgl.org/index.php?title=Slick-Util_Library_-_Part_1_-_Loading_Images_for_LWJGL