Compiler is giving nosuchelement exception

Every time I take input from Scanner the compiler is giving no such element exception.The program is compiling just fine in other compilers

Hello @mvarish2,

Are you writing your code in java?

no such element exception is thrown to indicate that there are no more elements in an enumeration.
This exception extends the RuntimeException class and thus, belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM). It is an unchecked exception and thus, it does not need to be declared in a method’s or a constructor’s throws clause.

Possible reason:
The error, java.util.NoSuchElementException is often thrown in the context of a Scanner when you call nextLine() and there’s no next line. You can cover this by checking for the next line before asking for it. Try something like:

if(scan.hasNextLine()){
String story = scan.nextLine();
}

Please, share your code.
This would help me in better understanding the mistake.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.