Showing posts with label NPE. Show all posts
Showing posts with label NPE. Show all posts

03 November 2013

Unboxing NPE in Java

It is very famous error, and you can find it in google very easy.

I am just trying to duplicating it here...

import java.util.List;
import java.util.ArrayList;

public class Unboxing{
    public static void main(String[] args){
        List<Integer> list = new ArrayList();
        list.add(getInteger());
        int x = list.get(0);
        System.out.printf("x value is %i\n", x);
    }

    private static Integer getInteger(){
        return null;
    }
}


And here's the result

$ java Unboxing 
Exception in thread "main" java.lang.NullPointerException
    at Unboxing.main(Unboxing.java:8)

That's all folks.