表达式的类型必须是数组类型,但它解析为BufferedImage [英] The type of the expression must be an array type but it resolved to BufferedImage

查看:698
本文介绍了表达式的类型必须是数组类型,但它解析为BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的很奇怪,错误在 textures [x]

It's being really weird, the error is at 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();
    }
}


推荐答案

正在重新使用您为数组提供的名称,您计划将其打包为单个元素的映像。您应该给它一个不同的名称,使其工作:

You are reusing the name that you gave to your array for the image that you are planning to parcel into individual elements. You should give it a different name to make it work:

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

这篇关于表达式的类型必须是数组类型,但它解析为BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆