小编jak*_*389的帖子

数组是必需的,但是找到了java.lang.String Java类数组错误

我收到以下错误:

array required, but java.lang.String found
Run Code Online (Sandbox Code Playgroud)

我不知道为什么。

我想做的是将一个对象的实例(我认为这是正确的术语)放入该类型的类(对象的)数组中。

我上课:

public class Player{
     public Player(int i){
           //somecodehere
     }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的main方法中创建它的一个实例:

static final Player[] a = new Player[5]; // this is where I'm trying to create the array.
public static void main(String[] args){
     Player p = new Player(1);
     a[0] = p; //this is the line that throws the error
}
Run Code Online (Sandbox Code Playgroud)

任何想法为什么会这样?

java arrays object instance

1
推荐指数
1
解决办法
2079
查看次数

标签 统计

arrays ×1

instance ×1

java ×1

object ×1