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 :)

5

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

Ouch... Tnx mate! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.