java lang nullpointer exception code example Example 1: nullpointerexception java Integer num; num = new Integer(10); Example 2: nullpointerexception java int x; x = 10;