0

FileReader.Read()当我认为应该从方法中填充时,它会给出一条消息:“空指针访问:变量 CharacterList 只能在此位置为空” :

public String[] ReadPeopleFile(String[] PeopleList, FileReader PeopleReader){
    char CharacterList[];///Soon parsed into a string list, by delimiting and separating into two string arrays,
    CharacterList = null;   
    String ParseString = null;
    try {
        PeopleReader.read(CharacterList);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    ParseString = CharacterList.toString();
    PeopleList = ParseString.split(";");

    return PeopleList;
}
4

1 回答 1

0

除非您分配 CharacterList,否则不会分配它。你需要更多这样的东西:

char characterList[] = new char[1000]; // I'm assuming that 1000 is enough here
int numChars = peopleReader.read(characterList); // I've changed PeopleReader to proper camel-case
String parseString = new String(characterList, 0, numChars);

我实际上在这里跳过了一些细节。您应该真正查看 API 文档FileReader,也许可以找到一些文件读取示例。

于 2013-10-30T19:33:42.977 回答