Runtime Error

Hello,
I was facing some Runtime Errors. Below is the code, for which I am getting java.lang.NullPointerException in the last line:-
15 java.io.BufferedReader r = new java.io.BufferedReader(new
16 java.io.InputStreamReader (System.in));
17 String a= r.readLine();
18 int x= Integer.parseInt(a.substring(0,a.indexOf(’ ')));
I cannot understand why there is an exception, although it is perfectly working in the offline IDE I use. Can you please tell how to resolve the problem?
Also, I wanted to know whether there are special differences between offline IDEs and Codechef IDE. Please tell me.
Regards.