这真的很奇怪,错误出现在textures[x]
处。
The type of the expression must be an array type but it resolved to BufferedImage
What is wrong with the code here?
static BufferedImage textures[][] = new BufferedImage[20][20];
public static void loadTextures()
{
try
{
//Loads The Image
BufferedImage textures = ImageIO.read(new URL("textures.png"));
for (int x = 0; x < 1280; x += 1)
{
for (int y = 0; y < 1280; y += 1)
{
textures[x][y] = textures.getSubimage(x*64, y*64, 64, 64);
}
}
} catch (Exception e)
{
e.printStackTrace();
}
}
最佳答案
您正在重复使用您为图像指定的数组名称,并将该图像打包为各个元素。您应该给它一个不同的名称以使其正常工作:
BufferedImage fullImage = ImageIO.read(new URL("textures.png"));
for (int x = 0; x < 1280; x += 1) {
for (int y = 0; y < 1280; y += 1) {
textures[x][y] = fullImage.getSubimage(x*64, y*64, 64, 64);
}
}
关于java - 表达式的类型必须是数组类型,但它解析为 BufferedImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13504225/