将房间数组转换为字符串数组时接收空指针异常

时间:2016-07-04 16:38:51

标签: java arrays

我有一个Room类的Array对象,它有一个toString方法。我想使用Room []并使用列表中每个房间对象的toString方法将其转换为String []。运行时我得到一个空指针异常。这里是我的代码片段(eclipse声明的方法是抛出错误)。

public String [] getDescriptions(){

    String[] descriptionList = new String[5];
    int boardNumber = 0;
    for (Room current : this.board) {
        descriptionList[boardNumber] = current.toString();
        boardNumber++;
    }
    return descriptionList;
}

提前谢谢。

0 个答案:

没有答案
相关问题