Null pointer access: The variable data can only be null at this location

android, eclipse, java

Solution

Seem like you required dynamic list, so what you need is replace `String[] data = null;` to use List

List data = new ArrayList<String>();
String[] data2 = null;
String[] datas = res.split("(s1)");
         
int i1 = 0;
int i2 = 0;
     
for (String datasx : datas) {
    i1++;
    String[] datas2 = datasx.split("(s2)");

    for (String datas2x : datas2) {
        String[] odcinek = datas2x.split("(s3)");
        data.add(odcinek[1] + "////" + odcinek[2] + "////" + odcinek[6]);
        i2++;
    }
}

Problem

Okay, that's what I've got: ``` String[] data = null; String[] data2 = null; String[] datas = res.split("(s1)"); int i1 = 0; int i2 = 0; for(String datasx : datas) { i1++; String[] datas2 = datasx.split("(s2)"); for(String datas2x : datas2) { String[] odcinek = datas2x.split("(s3)"); data[i2] = odcinek[1] + "////" + odcinek[2] + "////" + odcinek[6]; i2++; } } ``` And it's not working. Application crashes on this line: ``` data[i2] = odcinek[1] + "////" + odcinek[2] + "////" + odcinek[6]; ``` Actually, Eclipse gives me the following warning on it: Null pointer access: The variable data can only be null at this location but I have no idea what's wrong. Can anybody help? Thanks.

Original source

Related problems