2

I have class like this:

public class Info{ 
public static String id;
public static ArrayList<String> poruceno;
}

And now I am trying to populate arraylist 'poruceno' from another class:

Info info;
info.id="bla bla bla" //works perfectly
info.poruceno.add("some string"); //Returns null pointer exception :(

I need to add elements from many other classes to this ArrayList 'poruceno' from class Info. Please help :)

Darman
  • 71
  • 1
  • 3
  • 12

1 Answers1

3

first at all, do init the list at the point of defining it:

public class Info{ 
    public static String id;
    public static List<String> poruceno= new ArrayList<String>();
}

then use it from other classes

Info.poruceno.add("Hello");
Info.poruceno.add("World");
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97