-1

I am Beginner in java ,I am just trying out to convert string into char array,though it is running fine on my System but on a competitive coding website it is throwing an error.Here is the link of that Question Exception in thread "main" java.lang.NullPointerException

enter image description here

Here is my piece of code I have used BufferedReader to take input:-

                String s1;
                s1= inp.readLine();
                String s2;
                s2=s1;
                char ch1[] = s1.toCharArray();
                char ch2[] = s2.toCharArray();

Please help!

Vinit Raj
  • 1,900
  • 1
  • 15
  • 16

1 Answers1

0

You didn't initialize String s1 so its value is null and you get a NullPointerException. Initialize s1 with String s1 = ""; This should already work. Otherwise just use for test case and for the beginning a random value to initialize.

EDIT:

Dominik 105
  • 74
  • 1
  • 8