缓冲读取器上的NullPointerException

时间:2013-12-09 19:05:17

标签: java android nullpointerexception

我有这么简单的代码让我头疼

BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open("Quiz.csv")));

List<String> lines = null;
String line = null;

try {
    while ((line = reader.readLine()) != null) {
            lines.add(line);
        }
}
catch (Exception e)
{
    Log.e(getLocalClassName(), e.toString());
}

当我点击while循环时,我从logcat得到nullPointerException

2 个答案:

答案 0 :(得分:3)

您的行为空。初始化:

List<String> lines = new ArrayList<String>();

答案 1 :(得分:0)

你必须像这样初始化行:

List<String> lines = new ArrayList<String>();