-7

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]);
1
  • I see the error, but you should post the stack trace. Also you should look up a null pointer exception and try to find it for your self: stackoverflow.com/questions/218384/… Commented May 25, 2015 at 19:12

1 Answer 1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.