表达式的类型必须是数组类型,但它解析为Class<Character>

问题描述 投票:0回答:1

我正在尝试在构造函数中使用 2 个输入参数创建一个二维字符数组。 当我尝试创建数组时收到此错误:

The type of the expression must be an array type but it resolved to Class<Character>
.

这是我创建这个动态数组的尝试:

public class Screen {
    int Width;
    int Height;
    char[][] Display;
    String lightness = "@BR*#$PX0woIcv:+!~.,";
    
    Screen(int Width, int Height) {
        this.Width = Width;
        this.Height = Height;
        Display = char[Width][Height];
    }

    //rest of the methods...
}
java arrays char
1个回答
0
投票

第 9 行缺少

new
,这不是定义
Display
变量的方法。

Display = char[Width][Height];

© www.soinside.com 2019 - 2024. All rights reserved.