I am writing a simple java code but it gave me error of NullPointerException. My code is
String s="google";
ArrayList ss[]=new ArrayList[2];
ss[0].add(s);
System.out.println(ss[0]);
I am writing a simple java code but it gave me error of NullPointerException. My code is
String s="google";
ArrayList ss[]=new ArrayList[2];
ss[0].add(s);
System.out.println(ss[0]);
When you create the array, you do not create each element of the array. This will work:
ss[0] = new ArrayList();
ss[0].add(s);