Error only happen in codechef

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
System.out.println(a);

 }
}

Runtime error
NZEC

Error
Exception in thread “main” java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at Codechef.main(Main.java:13)

I’m a beginner, please give me some explanation and solution that I can understand.

If you are trying this code in codechef online ide, then make sure you give custom input also, before clicking on RUN.
If you click on SUBMIT, then you don’t need to enter custom input, because input data will automatically be given by the judge. But If you are clicking on RUN to check if your program works, then you have to provide custom input manually( On some other sites, clicking on run checks the program againts the sample test cases, but here is different.)

So basically when you clicked on RUN, the codechef ide could not find input buffer, so you got this error NoSuchElementFound , because there is no line of input found for Scanner.
Hope, you understand this.

6 Likes

Tysm, I believe codechef should change this, as its not at all intuitive. Thanks for the answer @gjaiswal108

1 Like

import java.util.;
import java.lang.
;

Correct this … than ur code would run