I'm trying to add numbers to an integer list but I'm receiving an error. Please refer my code

public class TstListofIntegers {

    public void testInteger() {
        List<Integer> listOfIntegers;

        for(Integer i=0;i<10;i++)


Error: System.NullPointerException: Attempt to de-reference a null object


Initialize your list List<Integer> listOfIntegers = new List<Integer>();

| improve this answer | |
  • 2
    alright , feel free to accept answer if its working for you ! there will be ✓ sign at left side. – Nachiket Deshpande Jan 9 '18 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.