Splitting error- IndexOutOfBoundsException

前端 未结 3 1590
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 23:07

I got stuck with an issue, that I can\'t seem to solve. When splitting I should be able to get id, name, check by setting row[0], row[1], row[2]. Strangely onl

3条回答
  •  佛祖请我去吃肉
    2021-01-24 23:47

    Try this code,

    ArrayList names = new ArrayList();
        try {
    
            DataInputStream dis = new DataInputStream(openFileInput(listLocation(listLoc)));
            BufferedReader br = new BufferedReader(new InputStreamReader(dis));
            String line;
            while ((line = br.readLine()) != null) {
                String[] row = line.split(",");
                //names.add(row[0]); // id
                names.add(row[1]); // name // ERROR AT THIS LINE
                //names.add(row[2]); // check
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    

    I think you don't need to use Pattern.quote(",") here.

提交回复
热议问题